HarmattanEvopediaApplication::HarmattanEvopediaApplication(int& argc, char** argv)
    : QApplication(argc, argv),
      view(new QDeclarativeView()),
      evopedia(new Evopedia()),
      settings(new EvopediaSettings(evopedia.data())),
      languageListModel(new QStringListModelForQML("name")),
      titleListModel(new TitleListModel()) {

    searchPrefix = "";

    // Set up the models
    languageListModel->setStringList(settings->getLanguageList());
    titleListModel->setTitleIterator(TitleIterator());

    // Export some C++ objects to QML.
    view->rootContext()->setContextProperty("languageListModel", languageListModel.data());
    view->rootContext()->setContextProperty("titlesModel", titleListModel.data());
    view->rootContext()->setContextProperty("evopedia", this);
    view->rootContext()->setContextProperty("evopediaSettings", settings.data());

    // Set up the view
    view->setSource(QUrl("qrc:/Main.qml"));
    view->setAttribute(Qt::WA_OpaquePaintEvent);
    view->setAttribute(Qt::WA_NoSystemBackground);
    view->viewport()->setAttribute(Qt::WA_OpaquePaintEvent);
    view->viewport()->setAttribute(Qt::WA_NoSystemBackground);

    view->showFullScreen();

    connect(settings.data(), SIGNAL(languageIndexChanged()), this, SLOT(refreshSearchResults()));
    connect(this, SIGNAL(searchPrefixChanged()), this, SLOT(refreshSearchResults()));

    refreshSearchResults();
}
void HarmattanEvopediaApplication::refreshSearchResults()
{
    if (settings->getLanguageIndex() == -1) {
        titleListModel->setTitleIterator(TitleIterator());
        return;
    }

    QString lang = settings->getLanguageList()[settings->getLanguageIndex()];

    LocalArchive *backend = evopedia->getArchiveManager()->getLocalArchive(lang);

    if (backend == NULL) {
        titleListModel->setTitleIterator(TitleIterator());
        return;
    }

    TitleIterator it = backend->getTitlesWithPrefix(searchPrefix);
    titleListModel->setTitleIterator(it);
}
Exemplo n.º 3
0
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();
        }
    }
}