2 * Copyright (C) 2010 Ixonos Plc.
4 * This file is part of fosdem-schedule.
6 * fosdem-schedule is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation, either version 2 of the License, or (at your option)
11 * fosdem-schedule is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * You should have received a copy of the GNU General Public License along with
17 * fosdem-schedule. If not, see <http://www.gnu.org/licenses/>.
19 #include "conferenceeditor.h"
21 #include "conferencemodel.h"
22 #include "urlinputdialog.h"
23 #include "mapwindow.h"
24 #include "errormessage.h"
26 #include <QInputDialog>
27 #include <QItemSelectionModel>
28 #include <QFileDialog>
29 #include <QMessageBox>
31 ConferenceEditor::ConferenceEditor(ConferenceModel* model, QWidget* parent)
39 confView->setModel(model);
41 QItemSelectionModel* confViewSelection = new QItemSelectionModel(model, this);
42 confView->setSelectionModel(confViewSelection);
44 connect(confViewSelection, SIGNAL(currentChanged(const QModelIndex&, const QModelIndex&)),
45 SLOT(itemSelected(const QModelIndex&, const QModelIndex&)));
46 connect(this, SIGNAL(wantCurrent(const QModelIndex&, QItemSelectionModel::SelectionFlags)),
47 confViewSelection, SLOT(setCurrentIndex(const QModelIndex&, QItemSelectionModel::SelectionFlags)));
48 connect(addBtn, SIGNAL(clicked()), SLOT(addClicked()));
49 connect(removeBtn, SIGNAL(clicked()), SLOT(removeClicked()));
50 connect(changeUrl, SIGNAL(clicked()), SLOT(changeUrlClicked()));
51 connect(refreshBtn, SIGNAL(clicked()), SLOT(refreshClicked()));
52 connect(showMapButton, SIGNAL(clicked()), SLOT(conferenceMapClicked()));
53 connect(buttonBox, SIGNAL(rejected()), SLOT(close()));
55 // it's OK to emit selection signals here
56 // because they are not yet connected to anybody
57 int active_id = Conference::activeConference();
59 emit wantCurrent(model->indexFromId(active_id), QItemSelectionModel::SelectCurrent);
61 itemSelected(QModelIndex(), QModelIndex());
65 void ConferenceEditor::conferenceRemoved()
67 if (model->rowCount() > 0) {
68 emit wantCurrent(model->index(0, 0), QItemSelectionModel::SelectCurrent);
70 itemSelected(QModelIndex(), QModelIndex());
74 void ConferenceEditor::itemSelected(const QModelIndex& current, const QModelIndex& previous)
76 // TODO: fill all required fields
78 if (!current.isValid()) {
81 emit noneConferenceSelected();
83 conferenceInfo->setCurrentIndex(1);
86 const Conference& conf = model->conferenceFromIndex(current);
87 selected_id = conf.id();
89 emit haveConferenceSelected(selected_id);
91 conferenceTitle->setText(conf.title());
92 conferenceSubtitle->setText(conf.subtitle());
93 conferenceWhere->setText(conf.city() + ", " + conf.venue());
94 conferenceWhen->setText(
95 conf.start().toString("dd-MM-yyyy")
97 conf.end().toString("dd-MM-yyyy"));
99 QString map = conf.map();
101 showMapButton->hide();
103 showMapButton->show();
106 conferenceInfo->setCurrentIndex(0);
111 void ConferenceEditor::addClicked()
113 UrlInputDialog url_input(this);
114 switch (url_input.exec()) {
115 case UrlInputDialog::HaveUrl: emit haveConferenceUrl(url_input.url()); break;
116 case UrlInputDialog::HaveFile: emit haveConferenceFile(url_input.url()); break;
117 case UrlInputDialog::Cancel: return;
121 void ConferenceEditor::removeClicked()
123 if (selected_id < 0) {
124 // TODO: disable it when none is selected
128 QMessageBox::StandardButton answer =
129 QMessageBox::question(0
130 , "Deletion confirmation"
131 , QString("Really delete the %1 conference").arg(Conference::getById(selected_id).title())
132 , QMessageBox::Yes | QMessageBox::No
135 if (answer == QMessageBox::Yes) {
136 emit removeConferenceRequested(selected_id);
140 void ConferenceEditor::changeUrlClicked()
142 if (selected_id < 0) {
145 const Conference& selected = Conference::getById(selected_id);
148 QString url = QInputDialog::getText(this, "URL Input", "Enter schedule URL", QLineEdit::Normal, selected.url(), &ok);
151 emit changeUrlRequested(selected_id, url);
155 void ConferenceEditor::refreshClicked()
157 if (selected_id < 0) {
160 const Conference& selected = Conference::getById(selected_id);
162 QString url = selected.url();
164 if (!url.isEmpty()) {
165 emit haveConferenceUrl(url);
167 static const QString format("Schedule URL for %1 is not set. Enter the schedule URL:");
169 QString url = QInputDialog::getText(this, "URL Input", format.arg(selected.title()), QLineEdit::Normal, QString(), &ok);
172 // first save it, to remain if fetch fails
173 emit changeUrlRequested(selected_id, url);
175 emit haveConferenceUrl(url);
180 void ConferenceEditor::importStarted()
184 buttons->layout()->removeItem(buttonsSpacer);
185 progressBar->setValue(0);
188 QApplication::processEvents();
191 void ConferenceEditor::showParsingProgress(int progress)
193 progressBar->setValue(progress);
195 QApplication::processEvents();
198 void ConferenceEditor::importFinished(const QString& title)
200 qDebug() << __PRETTY_FUNCTION__ << title;
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
206 buttons->layout()->addItem(buttonsSpacer);
209 QApplication::processEvents();
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);
219 itemSelected(QModelIndex(), QModelIndex());
222 void ConferenceEditor::conferenceMapClicked()
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");
233 QPixmap map(mapPath);
234 MapWindow window(map,roomName,this);