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"
25 #include <QInputDialog>
26 #include <QItemSelectionModel>
27 #include <QFileDialog>
28 #include <QMessageBox>
30 ConferenceEditor::ConferenceEditor(ConferenceModel* model, QWidget* parent)
38 confView->setModel(model);
40 QItemSelectionModel* confViewSelection = new QItemSelectionModel(model, this);
41 confView->setSelectionModel(confViewSelection);
43 connect(confViewSelection, SIGNAL(currentChanged(const QModelIndex&, const QModelIndex&)),
44 SLOT(itemSelected(const QModelIndex&, const QModelIndex&)));
45 connect(this, SIGNAL(wantCurrent(const QModelIndex&, QItemSelectionModel::SelectionFlags)),
46 confViewSelection, SLOT(setCurrentIndex(const QModelIndex&, QItemSelectionModel::SelectionFlags)));
47 connect(addBtn, SIGNAL(clicked()), SLOT(addClicked()));
48 connect(removeBtn, SIGNAL(clicked()), SLOT(removeClicked()));
49 connect(changeUrl, SIGNAL(clicked()), SLOT(changeUrlClicked()));
50 connect(refreshBtn, SIGNAL(clicked()), SLOT(refreshClicked()));
51 connect(showMapButton, SIGNAL(clicked()), SLOT(conferenceMapClicked()));
52 connect(buttonBox, SIGNAL(rejected()), SLOT(close()));
54 // it's OK to emit selection signals here
55 // because they are not yet connected to anybody
56 int active_id = Conference::activeConference();
58 emit wantCurrent(model->indexFromId(active_id), QItemSelectionModel::SelectCurrent);
60 itemSelected(QModelIndex(), QModelIndex());
64 void ConferenceEditor::conferenceRemoved()
66 if (model->rowCount() > 0) {
67 emit wantCurrent(model->index(0, 0), QItemSelectionModel::SelectCurrent);
69 itemSelected(QModelIndex(), QModelIndex());
73 void ConferenceEditor::itemSelected(const QModelIndex& current, const QModelIndex& previous)
75 // TODO: fill all required fields
77 if (!current.isValid()) {
80 emit noneConferenceSelected();
82 conferenceInfo->setCurrentIndex(1);
85 const Conference& conf = model->conferenceFromIndex(current);
86 selected_id = conf.id();
88 emit haveConferenceSelected(selected_id);
90 conferenceTitle->setText(conf.title());
91 conferenceSubtitle->setText(conf.subtitle());
92 conferenceWhere->setText(conf.city() + ", " + conf.venue());
93 conferenceWhen->setText(
94 conf.start().toString("dd-MM-yyyy")
96 conf.end().toString("dd-MM-yyyy"));
97 conferenceInfo->setCurrentIndex(0);
102 void ConferenceEditor::addClicked()
104 UrlInputDialog url_input(this);
105 switch (url_input.exec()) {
106 case UrlInputDialog::HaveUrl: emit haveConferenceUrl(url_input.url()); break;
107 case UrlInputDialog::HaveFile: emit haveConferenceFile(url_input.url()); break;
108 case UrlInputDialog::Cancel: return;
112 void ConferenceEditor::removeClicked()
114 if (selected_id < 0) {
115 // TODO: disable it when none is selected
119 QMessageBox::StandardButton answer =
120 QMessageBox::question(0
121 , "Deletion confirmation"
122 , QString("Really delete the %1 conference").arg(Conference::getById(selected_id).title())
123 , QMessageBox::Yes | QMessageBox::No
126 if (answer == QMessageBox::Yes) {
127 emit removeConferenceRequested(selected_id);
131 void ConferenceEditor::changeUrlClicked()
133 if (selected_id < 0) {
136 const Conference& selected = Conference::getById(selected_id);
139 QString url = QInputDialog::getText(this, "URL Input", "Enter schedule URL", QLineEdit::Normal, selected.url(), &ok);
142 emit changeUrlRequested(selected_id, url);
146 void ConferenceEditor::refreshClicked()
148 if (selected_id < 0) {
151 const Conference& selected = Conference::getById(selected_id);
153 QString url = selected.url();
155 if (!url.isEmpty()) {
156 emit haveConferenceUrl(url);
158 static const QString format("Schedule URL for %1 is not set. Enter the schedule URL:");
160 QString url = QInputDialog::getText(this, "URL Input", format.arg(selected.title()), QLineEdit::Normal, QString(), &ok);
163 // first save it, to remain if fetch fails
164 emit changeUrlRequested(selected_id, url);
166 emit haveConferenceUrl(url);
171 void ConferenceEditor::importStarted()
175 buttons->layout()->removeItem(buttonsSpacer);
176 progressBar->setValue(0);
179 QApplication::processEvents();
182 void ConferenceEditor::showParsingProgress(int progress)
184 progressBar->setValue(progress);
186 QApplication::processEvents();
189 void ConferenceEditor::importFinished(const QString& title)
191 qDebug() << __PRETTY_FUNCTION__ << title;
193 // removeItem should be shown later, but it takes some time,
194 // and not looks good
195 // anyway it will be shown a bit later
197 buttons->layout()->addItem(buttonsSpacer);
200 QApplication::processEvents();
202 int num = model->rowCount();
203 for (int i = 0; i < num; i++) {
204 QModelIndex item = model->index(i, 0);
205 if (model->data(item) == title) {
206 emit wantCurrent(item, QItemSelectionModel::SelectCurrent);
210 itemSelected(QModelIndex(), QModelIndex());
213 void ConferenceEditor::conferenceMapClicked()
215 QString mapPath = QString(":/maps/campus.png");
216 if(!QFile::exists(mapPath))
217 mapPath = QString(":/maps/rooms/not-available.png");
221 QPixmap map(mapPath);
222 MapWindow window(map,roomName,this);