void EvopediaWebServer::readClient() { QTcpSocket* socket = (QTcpSocket*)sender(); if (!socket->canReadLine()) return; /* TODO1 wait for end of request header? peek? */ const QList<QByteArray> tokens = socket->readLine().split(' '); if (tokens[0] != "GET" || tokens.size() < 2) { outputHeader(socket, "404"); closeConnection(socket); return; } const QUrl url = QUrl::fromPercentEncoding(tokens[1]); QString path = url.path(); if (path.endsWith("skins/common/images/magnify-clip.png")) path = "/static/magnify-clip.png"; const QStringList pathParts = path.mid(1).split('/'); if (pathParts.length() < 1 || pathParts[0].isEmpty()) { outputIndexPage(socket); closeConnection(socket); return; } const QString &firstPart = pathParts[0]; if (firstPart == "static") { outputStatic(socket, pathParts); } else if (firstPart == "search") { outputSearchResult(socket, url.queryItemValue("q"), url.queryItemValue("lang")); } else if (firstPart == "map") { qreal lat = url.queryItemValue("lat").toDouble(); qreal lon = url.queryItemValue("lon").toDouble(); int zoom = url.queryItemValue("zoom").toInt(); mapViewRequested(lat, lon, zoom); } else if (firstPart == "random") { redirectRandom(socket, pathParts); } else if (firstPart == "math" || (firstPart == "wiki" && pathParts.length() >= 2 && pathParts[1] == "math")) { outputMathImage(socket, pathParts); } else if (firstPart == "wiki" || firstPart == "articles") { outputWikiPage(socket, pathParts); } else { outputHeader(socket, "404"); } closeConnection(socket); }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::Evopedia), titleListModel(new TitleListModel(this)) { titleListModel->setTitleIterator(TitleIterator()); ui->setupUi(this); Evopedia *evopedia = (static_cast<EvopediaApplication *>(qApp))->evopedia(); foreach (LocalArchive *b, evopedia->getArchiveManager()->getDefaultLocalArchives()) ui->languageChooser->addItem(b->getLanguage()); ui->listView->setModel(titleListModel); connect(evopedia->getArchiveManager(), SIGNAL(defaultLocalArchivesChanged(QList<LocalArchive*>)), SLOT(backendsChanged(QList<LocalArchive*>))); connect(evopedia->findChild<EvopediaWebServer *>("evopediaWebserver"), SIGNAL(mapViewRequested(qreal, qreal, uint)), SLOT(mapViewRequested(qreal,qreal,uint))); QActionGroup *network = new QActionGroup(this); network->addAction(ui->actionAuto); network->addAction(ui->actionAllow); network->addAction(ui->actionDeny); QActionGroup *access = new QActionGroup(this); access->addAction(ui->actionLocal); access->addAction(ui->actionNetwork); QSettings settings("Evopedia", "GUI"); int networkUse = settings.value("network use", 1).toInt(); evopedia->setNetworkUse(networkUse); if (networkUse < 0) ui->actionDeny->setChecked(true); else if (networkUse > 0) ui->actionAllow->setChecked(true); else ui->actionAuto->setChecked(true); if (evopedia->isPubliclyAccessible()) ui->actionNetwork->setChecked(true); else ui->actionLocal->setChecked(true); QString defaultLanguage = settings.value("default language", "").toString(); if (evopedia->getArchiveManager()->hasLanguage(defaultLanguage)) { for (int i = 0; i < ui->languageChooser->count(); i ++) { if (ui->languageChooser->itemText(i) == defaultLanguage) { ui->languageChooser->setCurrentIndex(i); break; } } } QPointF mapPos = settings.value("map pos", QPointF(10.7387413, 59.9138204)).toPointF(); int mapZoom = settings.value("map zoom", 15).toInt(); /* TODO1 this should be improved: any key press that is accepted by the searchField should go to the searchField */ /* TODO does not work setFocusPolicy(Qt::StrongFocus); setFocusProxy(ui->searchField); setFocus(); */ ui->searchField->setFocus(); mapWindow = new MapWindow(this); mapWindow->setPosition(mapPos.y(), mapPos.x(), mapZoom); dumpSettings = new DumpSettings(this); #ifndef Q_OS_SYMBIAN mapWindow->resize(600, 450); #endif #ifdef Q_WS_MAEMO_5 this->setAttribute(Qt::WA_Maemo5StackedWindow); mapWindow->setAttribute(Qt::WA_Maemo5StackedWindow); dumpSettings->setAttribute(Qt::WA_Maemo5StackedWindow); #endif ArchiveManager *archiveManager = evopedia->getArchiveManager(); if (archiveManager->getDefaultLocalArchives().isEmpty()) { QMessageBox::StandardButton answer = QMessageBox::question(this, tr("No Archives Configured"), tr("To be able to use evopedia you have to " "download a Wikipedia archive. " "This can be done from within evopedia " "via the menu option \"Archives\". " "If you only want to try out evopedia, " "you can use the language \"small\", which " "is a small version of the English Wikipedia.<br />" "Do you want to download an archive now?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); if (answer == QMessageBox::Yes) { dumpSettings->show(); archiveManager->updateRemoteArchives(); } } }