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()));
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 QString where = conf.city();
93 if (!conf.city().isEmpty() && !conf.venue().isEmpty()) where += ", ";
94 where += conf.venue();
95 conferenceWhere->setText(where);
96 conferenceWhen->setText(
97 conf.start().toString("yyyy-MM-dd")
99 conf.end().toString("yyyy-MM-dd"));
100 if (conf.hasUtcOffset()) {
101 conferenceUtcOffset->setText(QString::number(conf.utcOffset()) + " min");
103 conferenceUtcOffset->setText("N/A");
105 conferenceInfo->setCurrentIndex(0);
110 void ConferenceEditor::addClicked()
112 UrlInputDialog url_input(this);
113 switch (url_input.exec()) {
114 case UrlInputDialog::HaveUrl: emit haveConferenceUrl(url_input.url(), 0); break;
115 case UrlInputDialog::HaveFile: emit haveConferenceFile(url_input.url(), 0); break;
116 case UrlInputDialog::Cancel: return;
120 void ConferenceEditor::removeClicked()
122 if (selected_id < 0) {
123 // TODO: disable it when none is selected
127 QMessageBox::StandardButton answer =
128 QMessageBox::question(0
129 , "Deletion confirmation"
130 , QString("Really delete the %1 conference").arg(Conference::getById(selected_id).title())
131 , QMessageBox::Yes | QMessageBox::No
134 if (answer == QMessageBox::Yes) {
135 emit removeConferenceRequested(selected_id);
139 void ConferenceEditor::changeUrlClicked()
141 if (selected_id < 0) return;
142 const Conference& selectedConf = Conference::getById(selected_id);
145 QString url = QInputDialog::getText(this, "URL Input", "Enter schedule URL", QLineEdit::Normal, selectedConf.url(), &ok);
148 emit changeUrlRequested(selected_id, url);
152 void ConferenceEditor::refreshClicked()
154 if (selected_id <= 0) return;
155 const Conference& selectedConf = Conference::getById(selected_id);
156 QString url = selectedConf.url();
159 static const QString format("Schedule URL for %1 is not set. Enter the schedule URL:");
161 url = QInputDialog::getText(this, "URL Input", format.arg(selectedConf.title()), QLineEdit::Normal, QString(), &ok);
163 // first save it, to remain if fetch fails
164 emit changeUrlRequested(selected_id, url);
167 importStarted(); // just to show the progress bar
168 emit haveConferenceUrl(url, selected_id);
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(int conferenceId) {
191 // removeItem should be shown later, but it takes some time,
192 // and not looks good
193 // anyway it will be shown a bit later
195 buttons->layout()->addItem(buttonsSpacer);
198 QApplication::processEvents();
200 QModelIndex item = model->indexFromId(conferenceId);
202 emit wantCurrent(item, QItemSelectionModel::SelectCurrent);
204 itemSelected(QModelIndex(), QModelIndex());