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()));
53 // it's OK to emit selection signals here
54 // because they are not yet connected to anybody
55 int active_id = Conference::activeConference();
57 emit wantCurrent(model->indexFromId(active_id), QItemSelectionModel::SelectCurrent);
59 itemSelected(QModelIndex(), QModelIndex());
63 void ConferenceEditor::conferenceRemoved()
65 if (model->rowCount() > 0) {
66 emit wantCurrent(model->index(0, 0), QItemSelectionModel::SelectCurrent);
68 itemSelected(QModelIndex(), QModelIndex());
72 void ConferenceEditor::itemSelected(const QModelIndex& current, const QModelIndex& previous)
74 // TODO: fill all required fields
76 if (!current.isValid()) {
79 emit noneConferenceSelected();
81 conferenceInfo->setCurrentIndex(1);
84 const Conference& conf = model->conferenceFromIndex(current);
85 selected_id = conf.id();
87 emit haveConferenceSelected(selected_id);
89 conferenceTitle->setText(conf.title());
90 conferenceSubtitle->setText(conf.subtitle());
91 conferenceWhere->setText(conf.city() + ", " + conf.venue());
92 conferenceWhen->setText(
93 conf.start().toString("dd-MM-yyyy")
95 conf.end().toString("dd-MM-yyyy"));
96 conferenceInfo->setCurrentIndex(0);
101 void ConferenceEditor::addClicked()
103 UrlInputDialog url_input(this);
104 switch (url_input.exec()) {
105 case UrlInputDialog::HaveUrl: emit haveConferenceUrl(url_input.url()); break;
106 case UrlInputDialog::HaveFile: emit haveConferenceFile(url_input.url()); break;
107 case UrlInputDialog::Cancel: return;
111 void ConferenceEditor::removeClicked()
113 if (selected_id < 0) {
114 // TODO: disable it when none is selected
118 QMessageBox::StandardButton answer =
119 QMessageBox::question(0
120 , "Deletion confirmation"
121 , QString("Really delete the %1 conference").arg(Conference::getById(selected_id).title())
122 , QMessageBox::Yes | QMessageBox::No
125 if (answer == QMessageBox::Yes) {
126 emit removeConferenceRequested(selected_id);
130 void ConferenceEditor::changeUrlClicked()
132 if (selected_id < 0) {
135 const Conference& selected = Conference::getById(selected_id);
138 QString url = QInputDialog::getText(this, "URL Input", "Enter schedule URL", QLineEdit::Normal, selected.url(), &ok);
141 emit changeUrlRequested(selected_id, url);
145 void ConferenceEditor::refreshClicked()
147 if (selected_id < 0) {
150 const Conference& selected = Conference::getById(selected_id);
152 QString url = selected.url();
154 if (!url.isEmpty()) {
155 emit haveConferenceUrl(url);
157 static const QString format("Schedule URL for %1 is not set. Enter the schedule URL:");
159 QString url = QInputDialog::getText(this, "URL Input", format.arg(selected.title()), QLineEdit::Normal, QString(), &ok);
162 // first save it, to remain if fetch fails
163 emit changeUrlRequested(selected_id, url);
165 emit haveConferenceUrl(url);
170 void ConferenceEditor::importStarted()
174 buttons->layout()->removeItem(buttonsSpacer);
175 progressBar->setValue(0);
178 QApplication::processEvents();
181 void ConferenceEditor::showParsingProgress(int progress)
183 progressBar->setValue(progress);
185 QApplication::processEvents();
188 void ConferenceEditor::importFinished(const QString& title)
190 qDebug() << __PRETTY_FUNCTION__ << title;
192 // removeItem should be shown later, but it takes some time,
193 // and not looks good
194 // anyway it will be shown a bit later
196 buttons->layout()->addItem(buttonsSpacer);
199 QApplication::processEvents();
201 int num = model->rowCount();
202 for (int i = 0; i < num; i++) {
203 QModelIndex item = model->index(i, 0);
204 if (model->data(item) == title) {
205 emit wantCurrent(item, QItemSelectionModel::SelectCurrent);
209 itemSelected(QModelIndex(), QModelIndex());
212 void ConferenceEditor::conferenceMapClicked()
214 QString mapPath = QString(":/maps/campus.png");
215 if(!QFile::exists(mapPath))
216 mapPath = QString(":/maps/rooms/not-available.png");
220 QPixmap map(mapPath);
221 MapWindow window(map,roomName,this);