Changeset b431d47 in confclerk_git for src/gui/mainwindow.cpp
- Timestamp:
- 04/22/10 16:26:31 (13 years ago)
- Branches:
- master, qt5
- Children:
- 7c6cf5e
- Parents:
- a61c5f5
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/gui/mainwindow.cpp
ra61c5f5 rb431d47 22 22 #include <QFile> 23 23 #include <QNetworkProxy> 24 #include <QNetworkAccessManager> 25 #include <QNetworkReply> 24 26 25 27 #include <sqlengine.h> … … 33 35 #include <QDialog> 34 36 #include <QMessageBox> 37 35 38 #include "ui_about.h" 36 39 #include <eventdialog.h> 37 40 #include "daynavigatorwidget.h" 38 #include "importschedulewidget.h"39 41 #include "mapwindow.h" 40 42 #include "settingsdialog.h" 43 #include "conferenceeditor.h" 44 #include "schedulexmlparser.h" 45 #include "errormessage.h" 41 46 42 47 #include <tabcontainer.h> … … 48 53 MainWindow::MainWindow(int aEventId, QWidget *aParent) 49 54 : QMainWindow(aParent) 55 , conferenceModel(new ConferenceModel(this)) 56 , mXmlParser(new ScheduleXmlParser(this)) 57 , mNetworkAccessManager(new QNetworkAccessManager(this)) 50 58 { 51 59 setupUi(this); … … 74 82 QNetworkProxy::setApplicationProxy(proxy); 75 83 76 int confId = Conference::activeConference(); 77 84 #if 0 85 // list of conferences must be maintained by ConferenceEditor 86 // here must be one of the signals from the closing ConferenceEditor (or model): 87 // selectedConf(conference), noConf() 78 88 connect(importScheduleWidget, SIGNAL(scheduleImported(int)), SLOT(scheduleImported(int))); 79 89 connect(importScheduleWidget, SIGNAL(scheduleDeleted(const QString&)), SLOT(scheduleDeleted(const QString&))); 90 #endif 80 91 81 92 // event details have changed … … 88 99 89 100 // event conference map button clicked 101 #if 0 102 // TODO: think about it when return to maps 90 103 connect(showMapButton, SIGNAL(clicked()), SLOT(conferenceMapClicked())); 104 #endif 91 105 92 106 connect(aboutAction, SIGNAL(triggered()), SLOT(aboutApp())); 93 107 connect(settingsAction, SIGNAL(triggered()), SLOT(setup())); 94 95 selectConference->setDuplicatesEnabled(false); 108 connect(conferencesAction, SIGNAL(triggered()), SLOT(showConferences())); 109 110 useConference(Conference::activeConference()); 111 112 #if 0 113 // TODO: remove GUI 114 // initialisation of model and pick active conference from there and call conferenceChanged() 115 // selectConference->setDuplicatesEnabled(false); 96 116 int confCount = Conference::getAll().count(); 97 117 if(confCount) 98 118 { 99 119 initTabs(); 100 fillAndShowConferenceHeader();120 // fillAndShowConferenceHeader(); 101 121 setWindowTitle(Conference::getById(confId).title()); 102 122 … … 106 126 { 107 127 Conference conf = i.next(); 108 selectConference->addItem(conf.title(),conf.id()); 128 // TODO: remove GUI 129 // selectConference->addItem(conf.title(),conf.id()); 109 130 } 110 int idx = selectConference->findText(Conference::getById(Conference::activeConference()).title()); 111 selectConference->setCurrentIndex(idx); 112 connect(selectConference, SIGNAL(currentIndexChanged(int)), SLOT(conferenceChanged(int))); 113 conferenceChanged(idx); 131 // TODO: remove GUI 132 // int idx = selectConference->findText(Conference::getById(Conference::activeConference()).title()); 133 // selectConference->setCurrentIndex(idx); 134 // connect(selectConference, SIGNAL(currentIndexChanged(int)), SLOT(conferenceChanged(int))); 135 // conferenceChanged(idx); 114 136 } 115 137 else 116 138 { 117 conferenceHeader->hide(); 118 selectConferenceWidget->hide(); 119 // go to the 'conferenceTab', so the user can import the schedule 120 tabWidget->setCurrentIndex(6); // 6 - conference tab 121 } 139 // TODO: remove GUI 140 // conferenceHeader->hide(); 141 // selectConferenceWidget->hide(); 142 // // go to the 'conferenceTab', so the user can import the schedule 143 // tabWidget->setCurrentIndex(6); // 6 - conference tab 144 } 145 #endif 122 146 123 147 // open dialog for given Event ID … … 133 157 catch(...) {} // just start application 134 158 } 159 160 connect(mNetworkAccessManager, SIGNAL(finished(QNetworkReply*)), SLOT(networkQueryFinished(QNetworkReply*))); 161 162 connect(mXmlParser, SIGNAL(parsingScheduleBegin()), conferenceModel, SLOT(newConferenceBegin())); 163 connect(mXmlParser, SIGNAL(parsingScheduleEnd(const QString&)), conferenceModel, SLOT(newConferenceEnd(const QString&))); 135 164 } 136 165 … … 138 167 { 139 168 Q_UNUSED(aConfId); 169 170 // TODO: this all goes to ConferenceEditor and model of conferences 171 #if 0 140 172 141 173 Conference conf = Conference::getById(aConfId); … … 156 188 conferenceChanged(idx); 157 189 } 190 #endif 158 191 } 159 192 160 193 void MainWindow::scheduleDeleted(const QString& title) 161 194 { 195 Q_UNUSED(title); 196 // TODO: this all goes to ConferenceEditor and model of conferences 197 #if 0 162 198 int idx = selectConference->findText(title); 163 199 … … 177 213 selectConference->removeItem(idx); 178 214 } 215 #endif 179 216 } 180 217 … … 213 250 } 214 251 215 void MainWindow::fillAndShowConferenceHeader() 252 void MainWindow::useConference(int id) 253 { 254 try { 255 Conference::getById(Conference::activeConference()).update("active",0); 256 Conference::getById(id).update("active",1); 257 258 initTabs(); 259 } catch (OrmException& e) { 260 // cannon set an active conference 261 unsetConference(); 262 return; 263 } 264 265 } 266 267 void MainWindow::initTabs() 216 268 { 217 269 int confId = Conference::activeConference(); 218 conferenceTitle->setText(Conference::getById(confId).title()); 219 conferenceSubtitle->setText(Conference::getById(confId).subtitle()); 220 conferenceWhere->setText(Conference::getById(confId).city() + ", " + Conference::getById(confId).venue()); 221 conferenceWhen->setText( 222 Conference::getById(confId).start().toString("dd-MM-yyyy") 223 + ", " + 224 Conference::getById(confId).end().toString("dd-MM-yyyy")); 225 conferenceHeader->show(); 226 } 227 228 void MainWindow::initTabs() 229 { 230 int confId = Conference::activeConference(); 231 QDate startDate = Conference::getById(confId).start(); 232 QDate endDate = Conference::getById(confId).end(); 270 Conference active = Conference::getById(confId); 271 QDate startDate = active.start(); 272 QDate endDate = active.end(); 273 setWindowTitle(active.title()); 233 274 234 275 // 'dayNavigator' emits signal 'dateChanged' after setting valid START:END dates … … 252 293 nowTabContainer->clearModel(); 253 294 254 conferenceHeader->hide(); 295 // TODO: remove 296 // conferenceHeader->hide(); 255 297 setWindowTitle(saved_title); 256 }257 258 void MainWindow::conferenceChanged(int aIndex)259 {260 if (aIndex < 0) {261 // no conferences left? reset all views262 unsetConference();263 return;264 }265 266 try {267 Conference::getById(Conference::activeConference()).update("active",0);268 Conference::getById(selectConference->itemData(aIndex).toInt()).update("active",1);269 } catch (OrmException& e) {270 // cannon set an active conference271 unsetConference();272 return;273 }274 275 initTabs();276 fillAndShowConferenceHeader();277 setWindowTitle(Conference::getById(Conference::activeConference()).title());278 298 } 279 299 … … 292 312 QNetworkProxy::setApplicationProxy(proxy); 293 313 } 314 315 /** Create and run ConferenceEditor dialog, making required connections for it. 316 317 This method manages, which classes actually perform changes in conference list. 318 319 There are several classes that modify the conferences: 320 this: 321 deletion and URL update. 322 this, mXmlParser and mNetworkAccessManager: 323 addition and refresh. 324 */ 325 void MainWindow::showConferences() 326 { 327 ConferenceEditor dialog(conferenceModel, this); 328 329 // TODO: connect signals about progress of network and parsing 330 331 connect(&dialog, SIGNAL(haveConferenceUrl(const QString&)), SLOT(importFromNetwork(const QString&))); 332 connect(&dialog, SIGNAL(haveConferenceFile(const QString&)), SLOT(importFromFile(const QString&))); 333 connect(&dialog, SIGNAL(removeConferenceRequested(int)), SLOT(removeConference(int))); 334 connect(&dialog, SIGNAL(changeUrlRequested(int, const QString&)), 335 SLOT(changeConferenceUrl(int, const QString&))); 336 337 connect(&dialog, SIGNAL(haveConferenceSelected(int)), SLOT(useConference(int))); 338 connect(&dialog, SIGNAL(noneConferenceSelected()), SLOT(unsetConference())); 339 340 connect(mXmlParser, SIGNAL(parsingScheduleBegin()), &dialog, SLOT(importStarted())); 341 connect(mXmlParser, SIGNAL(progressStatus(int)), &dialog, SLOT(showParsingProgress(int))); 342 connect(mXmlParser, SIGNAL(parsingScheduleEnd(const QString&)), &dialog, SLOT(importFinished(const QString&))); 343 344 connect(this, SIGNAL(conferenceRemoved()), &dialog, SLOT(conferenceRemoved())); 345 346 dialog.exec(); 347 } 348 349 void MainWindow::networkQueryFinished(QNetworkReply *aReply) 350 { 351 if ( aReply->error() != QNetworkReply::NoError ) 352 { 353 error_message(QString("Error occured during download: ") + aReply->errorString()); 354 } 355 else 356 { 357 qDebug() << __PRETTY_FUNCTION__ << ": have data"; 358 importData(aReply->readAll(), aReply->url().toEncoded()); 359 } 360 } 361 362 void MainWindow::importData(const QByteArray &aData, const QString& url) 363 { 364 // TODO: remove GUI 365 // instead send signals to the child dialog 366 #if 0 367 browse->hide(); 368 online->hide(); 369 progressBar->show(); 370 // proxySettings->hide(); 371 #endif 372 373 int confId = mXmlParser->parseData(aData, url); 374 375 #if 0 376 progressBar->hide(); 377 browse->show(); 378 online->show(); 379 // proxySettings->show(); 380 importScheduleLabel->setText("Schedule:"); 381 382 #endif 383 if (confId > 0) { 384 emit(scheduleImported(confId)); 385 } 386 } 387 388 void MainWindow::importFromNetwork(const QString& url) 389 { 390 qDebug() << __PRETTY_FUNCTION__; 391 QNetworkRequest request; 392 request.setUrl(QUrl(url)); 393 394 mNetworkAccessManager->setProxy(QNetworkProxy::applicationProxy()); 395 mNetworkAccessManager->get(request); 396 } 397 398 void MainWindow::importFromFile(const QString& filename) 399 { 400 qDebug() << __PRETTY_FUNCTION__; 401 QFile file(filename); 402 if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { 403 static const QString format("Cannot read \"%1\": error %2"); 404 error_message(format.arg(filename, QString::number(file.error()))); 405 } 406 407 importData(file.readAll(), ""); 408 } 409 410 void MainWindow::removeConference(int id) 411 { 412 Conference::deleteConference(id); 413 conferenceModel->conferenceRemoved(); 414 415 emit conferenceRemoved(); 416 } 417 418 void MainWindow::changeConferenceUrl(int id, const QString& url) 419 { 420 Conference::getById(id).setUrl(url); 421 } 422
Note: See TracChangeset
for help on using the changeset viewer.