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"
24 #include <QInputDialog>
25 #include <QItemSelectionModel>
26 #include <QFileDialog>
27 #include <QMessageBox>
29 ConferenceEditor::ConferenceEditor(ConferenceModel* model, QWidget* parent)
37 confView->setModel(model);
39 QItemSelectionModel* confViewSelection = new QItemSelectionModel(model, this);
40 confView->setSelectionModel(confViewSelection);
42 connect(confViewSelection, SIGNAL(currentChanged(const QModelIndex&, const QModelIndex&)),
43 SLOT(itemSelected(const QModelIndex&, const QModelIndex&)));
44 connect(this, SIGNAL(wantCurrent(const QModelIndex&, QItemSelectionModel::SelectionFlags)),
45 confViewSelection, SLOT(setCurrentIndex(const QModelIndex&, QItemSelectionModel::SelectionFlags)));
46 connect(addBtn, SIGNAL(clicked()), SLOT(addClicked()));
47 connect(removeBtn, SIGNAL(clicked()), SLOT(removeClicked()));
48 connect(changeUrl, SIGNAL(clicked()), SLOT(changeUrlClicked()));
49 connect(refreshBtn, SIGNAL(clicked()), SLOT(refreshClicked()));
51 // it's OK to emit selection signals here
52 // because they are not yet connected to anybody
53 int active_id = Conference::activeConference();
55 emit wantCurrent(model->indexFromId(active_id), QItemSelectionModel::SelectCurrent);
57 itemSelected(QModelIndex(), QModelIndex());
61 void ConferenceEditor::conferenceRemoved()
63 if (model->rowCount() > 0) {
64 emit wantCurrent(model->index(0, 0), QItemSelectionModel::SelectCurrent);
66 itemSelected(QModelIndex(), QModelIndex());
70 void ConferenceEditor::itemSelected(const QModelIndex& current, const QModelIndex& previous)
72 // TODO: fill all required fields
74 if (!current.isValid()) {
77 emit noneConferenceSelected();
79 conferenceInfo->setCurrentIndex(1);
82 const Conference& conf = model->conferenceFromIndex(current);
83 selected_id = conf.id();
85 emit haveConferenceSelected(selected_id);
87 conferenceTitle->setText(conf.title());
88 conferenceSubtitle->setText(conf.subtitle());
89 conferenceWhere->setText(conf.city() + ", " + conf.venue());
90 conferenceWhen->setText(
91 conf.start().toString("dd-MM-yyyy")
93 conf.end().toString("dd-MM-yyyy"));
94 conferenceInfo->setCurrentIndex(0);
99 void ConferenceEditor::addClicked()
101 UrlInputDialog url_input(this);
102 switch (url_input.exec()) {
103 case UrlInputDialog::HaveUrl: emit haveConferenceUrl(url_input.url()); break;
104 case UrlInputDialog::HaveFile: emit haveConferenceFile(url_input.url()); break;
105 case UrlInputDialog::Cancel: return;
109 void ConferenceEditor::removeClicked()
111 if (selected_id < 0) {
112 // TODO: disable it when none is selected
116 QMessageBox::StandardButton answer =
117 QMessageBox::question(0
118 , "Deletion confirmation"
119 , QString("Really delete the %1 conference").arg(Conference::getById(selected_id).title())
120 , QMessageBox::Yes | QMessageBox::No
123 if (answer == QMessageBox::Yes) {
124 emit removeConferenceRequested(selected_id);
128 void ConferenceEditor::changeUrlClicked()
130 if (selected_id < 0) {
133 const Conference& selected = Conference::getById(selected_id);
136 QString url = QInputDialog::getText(this, "URL Input", "Enter schedule URL", QLineEdit::Normal, selected.url(), &ok);
139 emit changeUrlRequested(selected_id, url);
143 void ConferenceEditor::refreshClicked()
145 if (selected_id < 0) {
148 const Conference& selected = Conference::getById(selected_id);
150 QString url = selected.url();
152 if (!url.isEmpty()) {
153 emit haveConferenceUrl(url);
155 static const QString format("Schedule URL for %1 is not set. Enter the schedule URL:");
157 QString url = QInputDialog::getText(this, "URL Input", format.arg(selected.title()), QLineEdit::Normal, QString(), &ok);
160 // first save it, to remain if fetch fails
161 emit changeUrlRequested(selected_id, url);
163 emit haveConferenceUrl(url);
168 void ConferenceEditor::importStarted()
172 buttons->layout()->removeItem(buttonsSpacer);
173 progressBar->setValue(0);
176 QApplication::processEvents();
179 void ConferenceEditor::showParsingProgress(int progress)
181 progressBar->setValue(progress);
183 QApplication::processEvents();
186 void ConferenceEditor::importFinished(const QString& title)
188 qDebug() << __PRETTY_FUNCTION__ << title;
190 buttons->layout()->addItem(buttonsSpacer);
193 QApplication::processEvents();
195 int num = model->rowCount();
196 for (int i = 0; i < num; i++) {
197 QModelIndex item = model->index(i, 0);
198 if (model->data(item) == title) {
199 emit wantCurrent(item, QItemSelectionModel::SelectCurrent);
203 itemSelected(QModelIndex(), QModelIndex());