2 * Copyright (C) 2010 Ixonos Plc.
3 * Copyright (C) 2011 Philipp Spitzer, gregor herrmann
5 * This file is part of ConfClerk.
7 * ConfClerk is free software: you can redistribute it and/or modify it
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)
12 * ConfClerk is distributed in the hope that it will be useful, but
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
17 * You should have received a copy of the GNU General Public License along with
18 * ConfClerk. If not, see <http://www.gnu.org/licenses/>.
20 #include "conferenceeditor.h"
22 #include "conferencemodel.h"
23 #include "urlinputdialog.h"
24 #include "mapwindow.h"
25 #include "errormessage.h"
27 #include <QInputDialog>
28 #include <QItemSelectionModel>
29 #include <QFileDialog>
30 #include <QMessageBox>
32 ConferenceEditor::ConferenceEditor(ConferenceModel* model, QWidget* parent)
40 confView->setModel(model);
42 QItemSelectionModel* confViewSelection = new QItemSelectionModel(model, this);
43 confView->setSelectionModel(confViewSelection);
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()));
53 connect(showMapButton, SIGNAL(clicked()), SLOT(conferenceMapClicked()));
54 connect(buttonBox, SIGNAL(rejected()), SLOT(close()));
56 // it's OK to emit selection signals here
57 // because they are not yet connected to anybody
58 int active_id = Conference::activeConference();
60 emit wantCurrent(model->indexFromId(active_id), QItemSelectionModel::SelectCurrent);
62 itemSelected(QModelIndex(), QModelIndex());
66 void ConferenceEditor::conferenceRemoved()
68 if (model->rowCount() > 0) {
69 emit wantCurrent(model->index(0, 0), QItemSelectionModel::SelectCurrent);
71 itemSelected(QModelIndex(), QModelIndex());
75 void ConferenceEditor::itemSelected(const QModelIndex& current, const QModelIndex& previous)
77 // TODO: fill all required fields
79 if (!current.isValid()) {
82 emit noneConferenceSelected();
84 conferenceInfo->setCurrentIndex(1);
87 const Conference& conf = model->conferenceFromIndex(current);
88 selected_id = conf.id();
90 emit haveConferenceSelected(selected_id);
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")
98 conf.end().toString("dd-MM-yyyy"));
100 QString map = conf.map();
102 showMapButton->hide();
104 showMapButton->show();
107 conferenceInfo->setCurrentIndex(0);
112 void ConferenceEditor::addClicked()
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;
122 void ConferenceEditor::removeClicked()
124 if (selected_id < 0) {
125 // TODO: disable it when none is selected
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
136 if (answer == QMessageBox::Yes) {
137 emit removeConferenceRequested(selected_id);
141 void ConferenceEditor::changeUrlClicked()
143 if (selected_id < 0) {
146 const Conference& selected = Conference::getById(selected_id);
149 QString url = QInputDialog::getText(this, "URL Input", "Enter schedule URL", QLineEdit::Normal, selected.url(), &ok);
152 emit changeUrlRequested(selected_id, url);
156 void ConferenceEditor::refreshClicked()
158 if (selected_id < 0) {
161 const Conference& selected = Conference::getById(selected_id);
163 QString url = selected.url();
165 if (!url.isEmpty()) {
166 emit haveConferenceUrl(url);
168 static const QString format("Schedule URL for %1 is not set. Enter the schedule URL:");
170 QString url = QInputDialog::getText(this, "URL Input", format.arg(selected.title()), QLineEdit::Normal, QString(), &ok);
173 // first save it, to remain if fetch fails
174 emit changeUrlRequested(selected_id, url);
176 emit haveConferenceUrl(url);
181 void ConferenceEditor::importStarted()
185 buttons->layout()->removeItem(buttonsSpacer);
186 progressBar->setValue(0);
189 QApplication::processEvents();
192 void ConferenceEditor::showParsingProgress(int progress)
194 progressBar->setValue(progress);
196 QApplication::processEvents();
199 void ConferenceEditor::importFinished(const QString& title)
201 qDebug() << __PRETTY_FUNCTION__ << title;
203 // removeItem should be shown later, but it takes some time,
204 // and not looks good
205 // anyway it will be shown a bit later
207 buttons->layout()->addItem(buttonsSpacer);
210 QApplication::processEvents();
212 int num = model->rowCount();
213 for (int i = 0; i < num; i++) {
214 QModelIndex item = model->index(i, 0);
215 if (model->data(item) == title) {
216 emit wantCurrent(item, QItemSelectionModel::SelectCurrent);
220 itemSelected(QModelIndex(), QModelIndex());
223 void ConferenceEditor::conferenceMapClicked()
225 Conference conf = Conference::getById(selected_id);
226 QString mapPath = conf.map();
227 if(mapPath.isEmpty() or !QFile::exists(mapPath)) {
228 error_message("Map is not available");
234 QPixmap map(mapPath);
235 MapWindow window(map,roomName,this);