source: src/gui/conferenceeditor.cpp @ cb7b999

qt5
Last change on this file since cb7b999 was cb7b999, checked in by kirilma <kirilma@…>, 12 years ago

restore viewing of conference map

  • Property mode set to 100644
File size: 6.7 KB
RevLine 
[b431d47]1/*
2 * Copyright (C) 2010 Ixonos Plc.
3 *
4 * This file is part of fosdem-schedule.
5 *
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)
9 * any later version.
10 *
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
14 * more details.
15 *
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/>.
18 */
19#include "conferenceeditor.h"
20
21#include "conferencemodel.h"
22#include "urlinputdialog.h"
[cb7b999]23#include "mapwindow.h"
[b431d47]24
25#include <QInputDialog>
26#include <QItemSelectionModel>
27#include <QFileDialog>
28#include <QMessageBox>
29
30ConferenceEditor::ConferenceEditor(ConferenceModel* model, QWidget* parent)
31: QDialog(parent)
32, model(model)
33, selected_id(-1)
34{
35    setupUi(this);
36    progressBar->hide();
37
38    confView->setModel(model);
39
40    QItemSelectionModel* confViewSelection = new QItemSelectionModel(model, this);
41    confView->setSelectionModel(confViewSelection);
42
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()));
[cb7b999]51    connect(showMapButton, SIGNAL(clicked()), SLOT(conferenceMapClicked()));
[b431d47]52
53    // it's OK to emit selection signals here
54    // because they are not yet connected to anybody
55    int active_id = Conference::activeConference();
56    if (active_id > 0) {
57        emit wantCurrent(model->indexFromId(active_id), QItemSelectionModel::SelectCurrent);
58    } else {
59        itemSelected(QModelIndex(), QModelIndex());
60    }
61}
62
63void ConferenceEditor::conferenceRemoved()
64{
65    if (model->rowCount() > 0) {
66        emit wantCurrent(model->index(0, 0), QItemSelectionModel::SelectCurrent);
67    } else {
68        itemSelected(QModelIndex(), QModelIndex());
69    }
70}
71
72void ConferenceEditor::itemSelected(const QModelIndex& current, const QModelIndex& previous)
73{
74    // TODO: fill all required fields
75    Q_UNUSED(previous);
76    if (!current.isValid()) {
77        selected_id = -1;
78
79        emit noneConferenceSelected();
80
81        conferenceInfo->setCurrentIndex(1);
82        removeBtn->hide();
83    } else {
84        const Conference& conf = model->conferenceFromIndex(current);
85        selected_id = conf.id();
86
87        emit haveConferenceSelected(selected_id);
88
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")
94                + ", " +
95                conf.end().toString("dd-MM-yyyy"));
96        conferenceInfo->setCurrentIndex(0);
97        removeBtn->show();
98    }
99}
100
101void ConferenceEditor::addClicked()
102{
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;
108    }
109}
110
111void ConferenceEditor::removeClicked()
112{
113    if (selected_id < 0) {
114        // TODO: disable it when none is selected
115        return;
116    }
117
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
123            , QMessageBox::No);
124
125    if (answer == QMessageBox::Yes) {
126        emit removeConferenceRequested(selected_id);
127    }
128}
129
130void ConferenceEditor::changeUrlClicked()
131{
132    if (selected_id < 0) {
133        return;
134    }
135    const Conference& selected = Conference::getById(selected_id);
136
137    bool ok;
138    QString url = QInputDialog::getText(this, "URL Input", "Enter schedule URL", QLineEdit::Normal, selected.url(), &ok);
139
140    if (ok) {
141        emit changeUrlRequested(selected_id, url);
142    }
143}
144
145void ConferenceEditor::refreshClicked()
146{
147    if (selected_id < 0) {
148        return;
149    }
150    const Conference& selected = Conference::getById(selected_id);
151
152    QString url = selected.url();
153
154    if (!url.isEmpty()) {
155        emit haveConferenceUrl(url);
156    } else {
157        static const QString format("Schedule URL for %1 is not set. Enter the schedule URL:");
158        bool ok;
159        QString url = QInputDialog::getText(this, "URL Input", format.arg(selected.title()), QLineEdit::Normal, QString(), &ok);
160
161        if (ok) {
162            // first save it, to remain if fetch fails
163            emit changeUrlRequested(selected_id, url);
164            // then fetch
165            emit haveConferenceUrl(url);
166        }
167    }
168}
169
170void ConferenceEditor::importStarted()
171{
172    addBtn->hide();
173    removeBtn->hide();
[f7dc75a]174    buttons->layout()->removeItem(buttonsSpacer);
[b431d47]175    progressBar->setValue(0);
176    progressBar->show();
177
178    QApplication::processEvents();
179}
180
181void ConferenceEditor::showParsingProgress(int progress)
182{
183    progressBar->setValue(progress);
184
185    QApplication::processEvents();
186}
187
188void ConferenceEditor::importFinished(const QString& title)
189{
190    qDebug() << __PRETTY_FUNCTION__ << title;
191    addBtn->show();
[66428e7]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
195    removeBtn->show();
[f7dc75a]196    buttons->layout()->addItem(buttonsSpacer);
[b431d47]197    progressBar->hide();
198
199    QApplication::processEvents();
200
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);
206            return;
207        }
208    }
209    itemSelected(QModelIndex(), QModelIndex());
210}
[cb7b999]211
212void ConferenceEditor::conferenceMapClicked()
213{
214    QString mapPath = QString(":/maps/campus.png");
215    if(!QFile::exists(mapPath))
216        mapPath = QString(":/maps/rooms/not-available.png");
217
218    QString roomName;
219
220    QPixmap map(mapPath);
221    MapWindow window(map,roomName,this);
222    window.exec();
223}
Note: See TracBrowser for help on using the repository browser.