예제 #1
0
TinyWebBrowser::TinyWebBrowser( QWidget* parent )
    : QWebView( parent ),
      d( 0 )
{
    connect( this, SIGNAL(statusBarMessage(QString)),
             this, SIGNAL(statusMessage(QString)) );

    page()->setLinkDelegationPolicy( QWebPage::DelegateAllLinks );
    connect( this, SIGNAL(linkClicked(QUrl)),
             this, SLOT(openExternalLink(QUrl)) );
    connect( this, SIGNAL(titleChanged(QString)),
             this, SLOT(setWindowTitle(QString)) );

    pageAction( QWebPage::OpenLinkInNewWindow )->setEnabled( false );
    pageAction( QWebPage::OpenLinkInNewWindow )->setVisible( false );
}
void HelpContentsView::onLinkClicked(const QUrl& url)
{
    // try to open as application
    if(openApplication(url))
    {
        return;
    }

    // try to open as remote link
    if(openExternalLink(url))
    {
        return;
    }

    // try to open as local link
    {
        openHelpContent(url);
        return;
    }
}
예제 #3
0
WikiOnBoard::WikiOnBoard(void* bgc, QWidget *parent) :
    QMainWindow(parent), m_bgc(bgc)

        {
        zimFileWrapper = new ZimFileWrapper(this);
	//For now assume that: S60 rd 3dition devices have no touch screen, all other devices have touch screen.
	// TODO Consider changing to QSystemDeviceInfo when Qt Mobility available for all supported devices
	hasTouchScreen = true;
	#ifdef Q_OS_SYMBIAN	
	if ((QSysInfo::s60Version()==QSysInfo::SV_S60_3_1) || (QSysInfo::s60Version()==QSysInfo::SV_S60_3_2)) {
		qDebug() << "S60 3rd edition device. Assume that no touchscreen is available.";
		hasTouchScreen = false;
	}
	#endif
        //Used by QSettings
        QCoreApplication::setOrganizationName(QLatin1String("Christian Puehringer"));
        QCoreApplication::setApplicationName(QLatin1String("WikiOnBoard"));

        #ifdef Q_OS_SYMBIAN
        // Save settings files to private application directory, to ensure
        // that uninstaller removes settings. (see also
        //  http://bugreports.qt.nokia.com/browse/QTBUG-16229)
            QSettings::setPath(QSettings::NativeFormat, QSettings::UserScope, QCoreApplication::applicationDirPath());
            QSettings::setPath(QSettings::IniFormat, QSettings::UserScope, QCoreApplication::applicationDirPath());
            QSettings::setPath(QSettings::NativeFormat, QSettings::SystemScope, QCoreApplication::applicationDirPath());
            QSettings::setPath(QSettings::IniFormat, QSettings::SystemScope, QCoreApplication::applicationDirPath());
        #endif
        qDebug() << "WikiOnBoard::WikiOnBoard. Version: " << QString::fromLocal8Bit(__APPVERSIONSTRING__) << " QT Version: "<<qVersion();
	qDebug() << " hasTouchScreen: "<<hasTouchScreen;
	


	QSettings settings;
	settings.beginGroup(QLatin1String("ZimFile"));

	QString lastZimFile = settings.value(QLatin1String("lastZimFile")).toString();
	settings.endGroup();

	ui.setupUi(this);
        articleViewer = new ArticleViewer(ui.articlePage,zimFileWrapper,hasTouchScreen);
        ui.gridLayout_3->addWidget(articleViewer);
        indexList = new IndexList(ui.indexPage,zimFileWrapper, hasTouchScreen);
        ui.gridLayout_2->addWidget(indexList,1,0);
        setStatusBar(0); //Remove status bar to increase useable screen size.
	//TODO still not perfect, quite some distance between
        //  widget and menu.

        settings.beginGroup(QLatin1String("UISettings"));
        fullScreen = settings.value(QLatin1String("fullScreen"), false).toBool();
        settings.endGroup();
        if (connect(articleViewer,SIGNAL(sourceChanged(QUrl)),this, SLOT(on_articleViewer_sourceChanged(QUrl)))) {
            qDebug() << "Connected sourceChanged";
        } else {
            qWarning()<<"Could not connect sourceChanged";
        }
        if (connect(articleViewer,SIGNAL(articleOpened(QString)),this, SLOT(onArticleOpened(QString)))) {
            qDebug() << "Connected articleOpened";
        } else {
            qWarning()<<"Could not connect articleOpened";
        }

        if (connect(articleViewer,SIGNAL(openExternalLink(QUrl)),this, SLOT(openExternalLink(QUrl)))) {
            qDebug() << "Connected openExternalLink";
        } else {
            qWarning()<<"Could not connect openExternalLink";
        }
        connect(QApplication::desktop(), SIGNAL(workAreaResized(int)), this, SLOT(workAreaResized(int)));

	
#ifdef Q_OS_SYMBIAN
	//Enable Softkeys in fullscreen mode. 
    //New Flag in Qt 4.6.3. 
	//Workaround used for 4.6.2 (see main.cpp for details) 
	//not working anymore with Qt 4.6.3
	//However, 4.6.2 workaround keep, as perhaps still
	// working/required for 4.6.2. 
	Qt::WindowFlags flags = windowFlags();
	flags |= Qt::WindowSoftkeysVisibleHint;
	setWindowFlags(flags);
        //Hide toolbar to increase useable screen space (toolbar may be used for meego).
        ui.toolBar->hide();
#endif
	if (fullScreen)
		{
                showFullScreen();
		}
	else
		{
		showMaximized();
		}
        openZimFileDialogAction = new QAction(tr("Open Zimfile"), this);
	connect(openZimFileDialogAction, SIGNAL(triggered()), this,
			SLOT(openZimFileDialog()));

        showWelcomePageAction = new QAction(tr("show Welcomepage"), this);
        connect(showWelcomePageAction, SIGNAL(triggered()), this,
                        SLOT(switchToWelcomePage()));
	gotoHomepageAction = new QAction(tr("Goto Homepage"), this);
	connect(gotoHomepageAction, SIGNAL(triggered()), this,
			SLOT(gotoHomepage()));
	aboutCurrentZimFileAction = new QAction(tr("About current Zimfile"), this);
	connect(aboutCurrentZimFileAction, SIGNAL(triggered()), this, 
			SLOT(aboutCurrentZimFile()));
	aboutAction = new QAction(tr("About"), this);
	connect(aboutAction, SIGNAL(triggered()), this,
			SLOT(about()));
	aboutQtAction = new QAction(tr("About Qt"), this);
	connect(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
				
		
	//Define search action (populates article list view with articles found searching for article
	//name line edit.
	// 
	searchArticleAction = new QAction(tr("Search Article"), this);

	connect(searchArticleAction, SIGNAL(triggered()), this,
			SLOT(searchArticle()));
	//connect(ui.articleName, SIGNAL(textChanged(QString)), searchArticleAction,
	//		SIGNAL(triggered())); //Automatically search after text changed
	//TODO: this hangs, instead textEdited used. find out why not working 
	connect(ui.articleName, SIGNAL(textEdited(QString)), searchArticleAction,
			SIGNAL(triggered())); //Automatically search after text changed


	ui.articleName->addAction(searchArticleAction);
	//Capitalize first letter. In particular important as zimlib
	// search is case-sensitive and in wikipedia most articles start with
	// captial letter.
	// Somewhat strange that this work. (Actually defaullt should be Imhnone
	// anyway, but appearantly it is not on symbian. Just calling ImhNone,
	// does not do anything, because it thinks that nothing has changed. 
	// Setting something different (here ImhPreferUppercase) and then ImhNone,
	// sets it to the desired Abc mode.
	ui.articleName->setInputMethodHints(Qt::ImhPreferUppercase); 
	ui.articleName->setInputMethodHints(Qt::ImhNone);
	clearSearchAction = new QAction(tr("Clear"), this);
	connect(clearSearchAction, SIGNAL(triggered()), ui.articleName,
				SLOT(clear()));
	connect(clearSearchAction, SIGNAL(triggered()), searchArticleAction,
					SIGNAL(triggered())); //Automatically search after cleared.

	this->addAction(clearSearchAction);
		
	openArticleAction = new QAction(tr("Open Article"), this);

        connect(indexList, SIGNAL(itemClicked(QListWidgetItem*)), this,
                        SLOT(articleListOpenArticle(QListWidgetItem *))); //For touchscreen devices
        //slot just calls openArticlAction.trigger
        connect(openArticleAction, SIGNAL(triggered()), this,
                        SLOT(articleListOpenArticle()));


        //connect(indexList, SIGNAL(itemActivated(QListWidgetItem*)), this, SLOT(articleListOpenArticle(QListWidgetItem *)));
        indexList->addAction(openArticleAction);

	//Open article when clicked or return key clicked. Note that for keypad phones return (amongst others) is
	// forwarded to articleListWidget, so that this works even if it has not focus.

	switchToIndexPageAction = new QAction(tr("Switch to index page"), this);
	connect(switchToIndexPageAction, SIGNAL(triggered()), this,
			SLOT(switchToIndexPage()));
	this->addAction(switchToIndexPageAction);

	//	ui.actionSearch->setSoftKeyRole(QAction::NegativeSoftKey); //Right softkey: return to search page
	///	ui.articlePage->addAction(ui.actionSearch);

	backArticleHistoryAction = new QAction(tr("Back"), this);
	connect(backArticleHistoryAction, SIGNAL(triggered()), this,
			SLOT(backArticleHistoryOrIndexPage()));
	this->addAction(backArticleHistoryAction); 
        emptyAction = new QAction( tr( "", "Empty. Displayed as right soft key if nothing opened"), this );
        addAction( emptyAction );

	toggleFullScreenAction = new QAction(tr("Toggle Fullscreen"), this); //TODO shortcut
	toggleFullScreenAction->setShortcutContext(Qt::ApplicationShortcut); //Or Qt::WindowShortcut?
	connect(toggleFullScreenAction, SIGNAL(triggered()), this,
			SLOT(toggleFullScreen()));
	this->addAction(toggleFullScreenAction);

        toggleImageDisplayAction = new QAction(tr("Show Images"), this);
        toggleImageDisplayAction->setCheckable(true);
        connect(toggleImageDisplayAction, SIGNAL(toggled(bool)), articleViewer,
                        SLOT(toggleImageDisplay(bool)));
        this->addAction(toggleImageDisplayAction);
        settings.beginGroup(QLatin1String("UISettings"));
        toggleImageDisplayAction->setChecked(settings.value(QLatin1String("showImages"), true).toBool());
        settings.endGroup();


	exitAction = new QAction(tr("Exit"), this);
	connect(exitAction, SIGNAL(triggered()), this, SLOT(close()));
	this->addAction(exitAction);

	zoomInAction = new QAction(tr("Zoom in"), this);
	zoomOutAction = new QAction(tr("Zoom out"), this);
        connect(zoomOutAction, SIGNAL(triggered()), articleViewer, SLOT(zoomOutOneStep()));
        connect(zoomInAction, SIGNAL(triggered()), articleViewer, SLOT(zoomInOneStep()));

        //Sub menus
        QMenu* optionsMenuIndexPage = new QMenu(tr("Options", "Option menu"),this);
        optionsMenuIndexPage->addAction(toggleFullScreenAction);
        optionsMenuIndexPage->addAction(toggleImageDisplayAction);
        QMenu* optionsMenuArticlePage = new QMenu(tr("Options", "Option menu"),this);
        optionsMenuArticlePage->addAction(zoomInAction);
        optionsMenuArticlePage->addAction(zoomOutAction);
        optionsMenuArticlePage->addAction(toggleFullScreenAction);
        optionsMenuArticlePage->addAction(toggleImageDisplayAction);
        QMenu* helpMenu = new QMenu(tr("Help", "Help menu"),this);
        helpMenu->addAction(showWelcomePageAction);
        helpMenu->addAction(gotoHomepageAction);
        helpMenu->addAction(aboutCurrentZimFileAction);
        helpMenu->addAction(aboutAction);
        helpMenu->addAction(aboutQtAction);


        menuIndexPage = new QMenu(this);
        menuIndexPage->addAction(openArticleAction);
        menuIndexPage->addAction(openZimFileDialogAction);
        menuIndexPage->addMenu(optionsMenuIndexPage);
        menuIndexPage->addMenu(helpMenu);
        menuIndexPage->addAction(exitAction);

        menuArticlePage = new QMenu(this);
        menuArticlePage->addAction(switchToIndexPageAction);
        menuArticlePage->addAction(openZimFileDialogAction);
        menuArticlePage->addMenu(optionsMenuArticlePage);
        menuArticlePage->addMenu(helpMenu);
        menuArticlePage->addAction(exitAction);

        menuArticlePageNoFileOpen = new QMenu(this);
        menuArticlePageNoFileOpen->addAction(openZimFileDialogAction);
        menuArticlePageNoFileOpen->addMenu(optionsMenuArticlePage);
        menuArticlePageNoFileOpen->addMenu(helpMenu);
        menuArticlePageNoFileOpen->addAction(exitAction);

        //Used to allow translation of softkey with menu.
        // (Actually should be translated automatically, but
        // appearantly not working, therefore just assign our
        // own (translatable) text)
        positiveSoftKeyActionMenuIndexPage = new QAction(tr("TRANLATOR Indexpage Menu Name"),this);
        positiveSoftKeyActionMenuIndexPage->setMenu(menuIndexPage);
        this->addAction(positiveSoftKeyActionMenuIndexPage);

        positiveSoftKeyActionMenuArticlePage = new QAction(tr("TRANLATOR Articlepage Menu Name"),this);
        positiveSoftKeyActionMenuArticlePage->setMenu(menuArticlePage);
        this->addAction(positiveSoftKeyActionMenuArticlePage);

        positiveSoftKeyActionMenuArticlePageNoFileOpen = new QAction(tr("TRANLATOR Articlepage (no zimfile open) Menu Name"),this);
        positiveSoftKeyActionMenuArticlePageNoFileOpen->setMenu(menuArticlePageNoFileOpen);
        this->addAction(positiveSoftKeyActionMenuArticlePageNoFileOpen);

         //Set welcome page
        QString zimDownloadUrl = QString(tr("http://cip.github.com/WikiOnBoard/Get-eBooks.html","Change link to page with localized zim files. (e.g http://cip.github.com/WikiOnBoard/Get-eBooks-DE.html"));
        QString getEBookLinkCaption = QString(tr("Download zimfile", "link"));
        QString zimDownloadUrlHtml = QString(tr("<a href=\"%1\">%2</a>", "DON'T translate this").arg(zimDownloadUrl,getEBookLinkCaption));
        QString informativeText = QString(tr("[TRANSLATOR] No zimfile selected. getEBook link  %1 opens url %3 with info where to get eBooks. Menu option %2 in option menu %4 opens zimfile on mobile", "Text is interpreted as HTML. Html for body and link (%1) automatically added. Other Html tags can be used if desired")).arg(zimDownloadUrlHtml,openZimFileDialogAction->text(),zimDownloadUrl, positiveSoftKeyActionMenuArticlePage->text());
        articleViewer->setWelcomePage(informativeText);

	// Set context menu policy for widgets to suppress the useless 'Actions' submenu
#ifdef Q_OS_SYMBIAN
	QWidgetList widgets = QApplication::allWidgets();
	QWidget* w = 0;
	foreach( w, widgets )
			{
			w->setContextMenuPolicy(Qt::NoContextMenu);
			}