[b431d47] | 1 | /* |
---|
| 2 | * Copyright (C) 2010 Ixonos Plc. |
---|
[68b2df2] | 3 | * Copyright (C) 2011 Philipp Spitzer, gregor herrmann |
---|
[b431d47] | 4 | * |
---|
[6df32f2] | 5 | * This file is part of ConfClerk. |
---|
[b431d47] | 6 | * |
---|
[6df32f2] | 7 | * ConfClerk is free software: you can redistribute it and/or modify it |
---|
[b431d47] | 8 | * under the terms of the GNU General Public License as published by the Free |
---|
| 9 | * Software Foundation, either version 2 of the License, or (at your option) |
---|
| 10 | * any later version. |
---|
| 11 | * |
---|
[6df32f2] | 12 | * ConfClerk is distributed in the hope that it will be useful, but |
---|
[b431d47] | 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
---|
| 14 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
---|
| 15 | * more details. |
---|
| 16 | * |
---|
| 17 | * You should have received a copy of the GNU General Public License along with |
---|
[6df32f2] | 18 | * ConfClerk. If not, see <http://www.gnu.org/licenses/>. |
---|
[b431d47] | 19 | */ |
---|
| 20 | #include "conferenceeditor.h" |
---|
| 21 | |
---|
| 22 | #include "conferencemodel.h" |
---|
| 23 | #include "urlinputdialog.h" |
---|
[cb7b999] | 24 | #include "mapwindow.h" |
---|
[cec47c6] | 25 | #include "errormessage.h" |
---|
[b431d47] | 26 | |
---|
| 27 | #include <QInputDialog> |
---|
| 28 | #include <QItemSelectionModel> |
---|
| 29 | #include <QFileDialog> |
---|
| 30 | #include <QMessageBox> |
---|
| 31 | |
---|
| 32 | ConferenceEditor::ConferenceEditor(ConferenceModel* model, QWidget* parent) |
---|
| 33 | : QDialog(parent) |
---|
| 34 | , model(model) |
---|
| 35 | , selected_id(-1) |
---|
| 36 | { |
---|
| 37 | setupUi(this); |
---|
| 38 | progressBar->hide(); |
---|
| 39 | |
---|
| 40 | confView->setModel(model); |
---|
| 41 | |
---|
| 42 | QItemSelectionModel* confViewSelection = new QItemSelectionModel(model, this); |
---|
| 43 | confView->setSelectionModel(confViewSelection); |
---|
| 44 | |
---|
| 45 | connect(confViewSelection, SIGNAL(currentChanged(const QModelIndex&, const QModelIndex&)), |
---|
| 46 | SLOT(itemSelected(const QModelIndex&, const QModelIndex&))); |
---|
| 47 | connect(this, SIGNAL(wantCurrent(const QModelIndex&, QItemSelectionModel::SelectionFlags)), |
---|
| 48 | confViewSelection, SLOT(setCurrentIndex(const QModelIndex&, QItemSelectionModel::SelectionFlags))); |
---|
| 49 | connect(addBtn, SIGNAL(clicked()), SLOT(addClicked())); |
---|
| 50 | connect(removeBtn, SIGNAL(clicked()), SLOT(removeClicked())); |
---|
| 51 | connect(changeUrl, SIGNAL(clicked()), SLOT(changeUrlClicked())); |
---|
| 52 | connect(refreshBtn, SIGNAL(clicked()), SLOT(refreshClicked())); |
---|
[cb7b999] | 53 | connect(showMapButton, SIGNAL(clicked()), SLOT(conferenceMapClicked())); |
---|
[3cdaf7d] | 54 | connect(buttonBox, SIGNAL(rejected()), SLOT(close())); |
---|
[b431d47] | 55 | |
---|
| 56 | // it's OK to emit selection signals here |
---|
| 57 | // because they are not yet connected to anybody |
---|
| 58 | int active_id = Conference::activeConference(); |
---|
| 59 | if (active_id > 0) { |
---|
| 60 | emit wantCurrent(model->indexFromId(active_id), QItemSelectionModel::SelectCurrent); |
---|
| 61 | } else { |
---|
| 62 | itemSelected(QModelIndex(), QModelIndex()); |
---|
| 63 | } |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | void ConferenceEditor::conferenceRemoved() |
---|
| 67 | { |
---|
| 68 | if (model->rowCount() > 0) { |
---|
| 69 | emit wantCurrent(model->index(0, 0), QItemSelectionModel::SelectCurrent); |
---|
| 70 | } else { |
---|
| 71 | itemSelected(QModelIndex(), QModelIndex()); |
---|
| 72 | } |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | void ConferenceEditor::itemSelected(const QModelIndex& current, const QModelIndex& previous) |
---|
| 76 | { |
---|
| 77 | // TODO: fill all required fields |
---|
| 78 | Q_UNUSED(previous); |
---|
| 79 | if (!current.isValid()) { |
---|
| 80 | selected_id = -1; |
---|
| 81 | |
---|
| 82 | emit noneConferenceSelected(); |
---|
| 83 | |
---|
| 84 | conferenceInfo->setCurrentIndex(1); |
---|
| 85 | removeBtn->hide(); |
---|
| 86 | } else { |
---|
| 87 | const Conference& conf = model->conferenceFromIndex(current); |
---|
| 88 | selected_id = conf.id(); |
---|
| 89 | |
---|
| 90 | emit haveConferenceSelected(selected_id); |
---|
| 91 | |
---|
| 92 | conferenceTitle->setText(conf.title()); |
---|
| 93 | conferenceSubtitle->setText(conf.subtitle()); |
---|
| 94 | conferenceWhere->setText(conf.city() + ", " + conf.venue()); |
---|
| 95 | conferenceWhen->setText( |
---|
| 96 | conf.start().toString("dd-MM-yyyy") |
---|
| 97 | + ", " + |
---|
| 98 | conf.end().toString("dd-MM-yyyy")); |
---|
[cec47c6] | 99 | |
---|
| 100 | QString map = conf.map(); |
---|
| 101 | if (map.isEmpty()) { |
---|
| 102 | showMapButton->hide(); |
---|
| 103 | } else { |
---|
| 104 | showMapButton->show(); |
---|
| 105 | } |
---|
| 106 | |
---|
[b431d47] | 107 | conferenceInfo->setCurrentIndex(0); |
---|
| 108 | removeBtn->show(); |
---|
| 109 | } |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | void ConferenceEditor::addClicked() |
---|
| 113 | { |
---|
| 114 | UrlInputDialog url_input(this); |
---|
| 115 | switch (url_input.exec()) { |
---|
| 116 | case UrlInputDialog::HaveUrl: emit haveConferenceUrl(url_input.url()); break; |
---|
| 117 | case UrlInputDialog::HaveFile: emit haveConferenceFile(url_input.url()); break; |
---|
| 118 | case UrlInputDialog::Cancel: return; |
---|
| 119 | } |
---|
| 120 | } |
---|
| 121 | |
---|
| 122 | void ConferenceEditor::removeClicked() |
---|
| 123 | { |
---|
| 124 | if (selected_id < 0) { |
---|
| 125 | // TODO: disable it when none is selected |
---|
| 126 | return; |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | QMessageBox::StandardButton answer = |
---|
| 130 | QMessageBox::question(0 |
---|
| 131 | , "Deletion confirmation" |
---|
| 132 | , QString("Really delete the %1 conference").arg(Conference::getById(selected_id).title()) |
---|
| 133 | , QMessageBox::Yes | QMessageBox::No |
---|
| 134 | , QMessageBox::No); |
---|
| 135 | |
---|
| 136 | if (answer == QMessageBox::Yes) { |
---|
| 137 | emit removeConferenceRequested(selected_id); |
---|
| 138 | } |
---|
| 139 | } |
---|
| 140 | |
---|
| 141 | void ConferenceEditor::changeUrlClicked() |
---|
| 142 | { |
---|
| 143 | if (selected_id < 0) { |
---|
| 144 | return; |
---|
| 145 | } |
---|
| 146 | const Conference& selected = Conference::getById(selected_id); |
---|
| 147 | |
---|
| 148 | bool ok; |
---|
| 149 | QString url = QInputDialog::getText(this, "URL Input", "Enter schedule URL", QLineEdit::Normal, selected.url(), &ok); |
---|
| 150 | |
---|
| 151 | if (ok) { |
---|
| 152 | emit changeUrlRequested(selected_id, url); |
---|
| 153 | } |
---|
| 154 | } |
---|
| 155 | |
---|
| 156 | void ConferenceEditor::refreshClicked() |
---|
| 157 | { |
---|
| 158 | if (selected_id < 0) { |
---|
| 159 | return; |
---|
| 160 | } |
---|
| 161 | const Conference& selected = Conference::getById(selected_id); |
---|
| 162 | |
---|
| 163 | QString url = selected.url(); |
---|
| 164 | |
---|
| 165 | if (!url.isEmpty()) { |
---|
| 166 | emit haveConferenceUrl(url); |
---|
| 167 | } else { |
---|
| 168 | static const QString format("Schedule URL for %1 is not set. Enter the schedule URL:"); |
---|
| 169 | bool ok; |
---|
| 170 | QString url = QInputDialog::getText(this, "URL Input", format.arg(selected.title()), QLineEdit::Normal, QString(), &ok); |
---|
| 171 | |
---|
| 172 | if (ok) { |
---|
| 173 | // first save it, to remain if fetch fails |
---|
| 174 | emit changeUrlRequested(selected_id, url); |
---|
| 175 | // then fetch |
---|
| 176 | emit haveConferenceUrl(url); |
---|
| 177 | } |
---|
| 178 | } |
---|
| 179 | } |
---|
| 180 | |
---|
| 181 | void ConferenceEditor::importStarted() |
---|
| 182 | { |
---|
| 183 | addBtn->hide(); |
---|
| 184 | removeBtn->hide(); |
---|
[f7dc75a] | 185 | buttons->layout()->removeItem(buttonsSpacer); |
---|
[b431d47] | 186 | progressBar->setValue(0); |
---|
| 187 | progressBar->show(); |
---|
| 188 | |
---|
| 189 | QApplication::processEvents(); |
---|
| 190 | } |
---|
| 191 | |
---|
| 192 | void ConferenceEditor::showParsingProgress(int progress) |
---|
| 193 | { |
---|
| 194 | progressBar->setValue(progress); |
---|
| 195 | |
---|
| 196 | QApplication::processEvents(); |
---|
| 197 | } |
---|
| 198 | |
---|
| 199 | void ConferenceEditor::importFinished(const QString& title) |
---|
| 200 | { |
---|
| 201 | addBtn->show(); |
---|
[66428e7] | 202 | // removeItem should be shown later, but it takes some time, |
---|
| 203 | // and not looks good |
---|
| 204 | // anyway it will be shown a bit later |
---|
| 205 | removeBtn->show(); |
---|
[f7dc75a] | 206 | buttons->layout()->addItem(buttonsSpacer); |
---|
[b431d47] | 207 | progressBar->hide(); |
---|
| 208 | |
---|
| 209 | QApplication::processEvents(); |
---|
| 210 | |
---|
| 211 | int num = model->rowCount(); |
---|
| 212 | for (int i = 0; i < num; i++) { |
---|
| 213 | QModelIndex item = model->index(i, 0); |
---|
| 214 | if (model->data(item) == title) { |
---|
| 215 | emit wantCurrent(item, QItemSelectionModel::SelectCurrent); |
---|
| 216 | return; |
---|
| 217 | } |
---|
| 218 | } |
---|
| 219 | itemSelected(QModelIndex(), QModelIndex()); |
---|
| 220 | } |
---|
[cb7b999] | 221 | |
---|
| 222 | void ConferenceEditor::conferenceMapClicked() |
---|
| 223 | { |
---|
[cec47c6] | 224 | Conference conf = Conference::getById(selected_id); |
---|
| 225 | QString mapPath = conf.map(); |
---|
| 226 | if(mapPath.isEmpty() or !QFile::exists(mapPath)) { |
---|
| 227 | error_message("Map is not available"); |
---|
| 228 | return; |
---|
| 229 | } |
---|
[cb7b999] | 230 | |
---|
| 231 | QString roomName; |
---|
| 232 | |
---|
| 233 | QPixmap map(mapPath); |
---|
| 234 | MapWindow window(map,roomName,this); |
---|
| 235 | window.exec(); |
---|
| 236 | } |
---|