2 * Copyright (C) 2010 Ixonos Plc.
3 * Copyright (C) 2011-2017 Philipp Spitzer, gregor herrmann, Stefan Stahl
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 "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(buttonBox, SIGNAL(rejected()), SLOT(close()));
53 connect(conferenceDtsHours, SIGNAL(valueChanged(int)), SLOT(dtsChanged()));
54 connect(conferenceDtsMinutes, SIGNAL(valueChanged(int)), SLOT(dtsChanged()));
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 QString where = conf.city();
95 if (!conf.city().isEmpty() && !conf.venue().isEmpty()) where += ", ";
96 where += conf.venue();
97 conferenceWhere->setText(where);
98 conferenceWhen->setText(
99 conf.start().toString("yyyy-MM-dd")
101 conf.end().toString("yyyy-MM-dd"));
102 if (conf.hasUtcOffset()) {
103 conferenceUtcOffset->setText(QString::number(conf.utcOffset()) + " min");
105 conferenceUtcOffset->setText("N/A");
107 int dts = conf.displayTimeShift();
108 conferenceDtsHours->setValue(dts / 60);
109 conferenceDtsMinutes->setValue(abs(dts) % 60);
110 conferenceInfo->setCurrentIndex(0);
115 void ConferenceEditor::addClicked()
117 UrlInputDialog url_input(this);
118 switch (url_input.exec()) {
119 case UrlInputDialog::HaveUrl: emit haveConferenceUrl(url_input.url(), 0); break;
120 case UrlInputDialog::HaveFile: emit haveConferenceFile(url_input.url(), 0); break;
121 case UrlInputDialog::Cancel: return;
125 void ConferenceEditor::removeClicked()
127 if (selected_id < 0) {
128 // TODO: disable it when none is selected
132 QMessageBox::StandardButton answer =
133 QMessageBox::question(0
134 , "Deletion confirmation"
135 , QString("Really delete the %1 conference").arg(Conference::getById(selected_id).title())
136 , QMessageBox::Yes | QMessageBox::No
139 if (answer == QMessageBox::Yes) {
140 emit removeConferenceRequested(selected_id);
144 void ConferenceEditor::changeUrlClicked()
146 if (selected_id < 0) return;
147 const Conference& selectedConf = Conference::getById(selected_id);
150 QString url = QInputDialog::getText(this, "URL Input", "Enter schedule URL", QLineEdit::Normal, selectedConf.url(), &ok);
153 emit changeUrlRequested(selected_id, url);
157 void ConferenceEditor::refreshClicked()
159 if (selected_id <= 0) return;
160 const Conference& selectedConf = Conference::getById(selected_id);
161 QString url = selectedConf.url();
164 static const QString format("Schedule URL for %1 is not set. Enter the schedule URL:");
166 url = QInputDialog::getText(this, "URL Input", format.arg(selectedConf.title()), QLineEdit::Normal, QString(), &ok);
168 // first save it, to remain if fetch fails
169 emit changeUrlRequested(selected_id, url);
172 importStarted(); // just to show the progress bar
173 emit haveConferenceUrl(url, selected_id);
176 void ConferenceEditor::dtsChanged() {
177 if (selected_id < 0) return;
178 Conference& conference = model->conferenceFromIndex(model->indexFromId(selected_id));
179 int minutes = conferenceDtsMinutes->value();
180 if (conferenceDtsHours->value() < 0) minutes *= -1;
181 conference.setDisplayTimeShift(conferenceDtsHours->value() * 60 + minutes);
184 void ConferenceEditor::importStarted()
188 buttons->layout()->removeItem(buttonsSpacer);
189 progressBar->setValue(0);
192 QApplication::processEvents();
195 void ConferenceEditor::showParsingProgress(int progress)
197 progressBar->setValue(progress);
199 QApplication::processEvents();
202 void ConferenceEditor::importFinished(int conferenceId) {
204 // removeItem should be shown later, but it takes some time,
205 // and not looks good
206 // anyway it will be shown a bit later
208 buttons->layout()->addItem(buttonsSpacer);
211 QApplication::processEvents();
213 QModelIndex item = model->indexFromId(conferenceId);
215 emit wantCurrent(item, QItemSelectionModel::SelectCurrent);
217 itemSelected(QModelIndex(), QModelIndex());