mirror of
git://projects.qi-hardware.com/qvido.git
synced 2024-12-22 14:42:24 +02:00
initial upload
Signed-off-by: Mirko Lindner <mirko@sharism.cc>
This commit is contained in:
commit
68c4971a2e
261
htmlarea.cpp
Normal file
261
htmlarea.cpp
Normal file
@ -0,0 +1,261 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* Copyright (C) 2010 by Mirko Lindner *
|
||||||
|
* mirko@sharism.cc *
|
||||||
|
* *
|
||||||
|
* This program is free software; you can redistribute it and/or modify *
|
||||||
|
* it under the terms of the GNU General Public License as published by *
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or *
|
||||||
|
* (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This program is distributed in the hope that it will be useful, *
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||||
|
* GNU General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU General Public License *
|
||||||
|
* along with this program; if not, write to the *
|
||||||
|
* Free Software Foundation, Inc., *
|
||||||
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
// #include <iostream>
|
||||||
|
#include <QtGui>
|
||||||
|
#include <QMessageBox>
|
||||||
|
#include <QTextBrowser>
|
||||||
|
#include <string>
|
||||||
|
#include <sstream>
|
||||||
|
// #include <vector>
|
||||||
|
#include "qmain.h"
|
||||||
|
#include <zim/file.h>
|
||||||
|
#include <zim/search.h>
|
||||||
|
#include <zim/fileimpl.h>
|
||||||
|
|
||||||
|
#include <cxxtools/log.h>
|
||||||
|
|
||||||
|
log_define("qvido.htmlarea");
|
||||||
|
|
||||||
|
///////////////////////////////////////////
|
||||||
|
// Functions related to htmlarea
|
||||||
|
void HtmlArea::linking( const QUrl &txt ){
|
||||||
|
QString str = txt.toString();
|
||||||
|
|
||||||
|
// // check if url is an internal anchor if yes jump if not end request and query zimlib
|
||||||
|
if (str.startsWith("#") == 1){
|
||||||
|
this->scrollToAnchor(str);
|
||||||
|
}else{
|
||||||
|
this->setSource(this->source());
|
||||||
|
this->setNewContent(1, str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void HtmlArea::setNewContent( int method, QString str = "" ){
|
||||||
|
zim::Article article;
|
||||||
|
|
||||||
|
if (method == 0){
|
||||||
|
article = this->getRandomArticle();
|
||||||
|
}else if( method == 1){
|
||||||
|
article = this->getArticleFromUrl(str);
|
||||||
|
}else if( method == 2){
|
||||||
|
// first search
|
||||||
|
zim::Search::Results result = this->searchArticleFromTitle(str);
|
||||||
|
// if result = 1 display article
|
||||||
|
if (result.size() == 1){
|
||||||
|
//create ZIM file accessor
|
||||||
|
zim::File file = this->get_file();
|
||||||
|
article = file.getArticle(result[0].getArticle().getIndex());
|
||||||
|
}
|
||||||
|
// if result > 1 display options return at end
|
||||||
|
else if (result.size() > 1){
|
||||||
|
QString res;
|
||||||
|
for (unsigned i = 0; i < result.size(); ++i)
|
||||||
|
{
|
||||||
|
res.append("<li><a href='" + QString::fromStdString(result[i].getArticle().getUrl()) + "'>" + QString::fromStdString(result[i].getArticle().getTitle()) + "</a></li>");
|
||||||
|
}
|
||||||
|
this->setText(res);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//check if article is valid, if display if not show error
|
||||||
|
if (article.good()){
|
||||||
|
//TODO build history, set Title
|
||||||
|
this->setText(QString::fromStdString(article.getPage()));
|
||||||
|
}else{
|
||||||
|
//construct error text
|
||||||
|
QString errText = "The article you requested (";
|
||||||
|
errText.append(str);
|
||||||
|
errText.append(") could not be found.");
|
||||||
|
|
||||||
|
//construct and display error box
|
||||||
|
QMessageBox::information(qobject_cast<QMain *>(this->parentWidget()), "Error",
|
||||||
|
errText,
|
||||||
|
QMessageBox::Close);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// // slots
|
||||||
|
// // TODO ...is there any way to connect setNewContent to Actions directly using default values?
|
||||||
|
void HtmlArea::getRandom(){
|
||||||
|
log_debug("getRandom called");
|
||||||
|
this->setNewContent( 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
void HtmlArea::searchArticle(QString term){
|
||||||
|
log_debug("searchArticle called");
|
||||||
|
this->setNewContent( 2 , term);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////
|
||||||
|
// Zimlib functions
|
||||||
|
|
||||||
|
const zim::File& HtmlArea::get_file()
|
||||||
|
{
|
||||||
|
static zim::File zimFile;
|
||||||
|
|
||||||
|
if (!zimFile.good())
|
||||||
|
{
|
||||||
|
zimFile = zim::File(qobject_cast<QMain *>(this->parentWidget())->fileLocation);
|
||||||
|
log_debug("number of articles: " << zimFile.getCountArticles());
|
||||||
|
}
|
||||||
|
|
||||||
|
return zimFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
//get random article
|
||||||
|
//TODO get new article if article returned is current article
|
||||||
|
zim::Article HtmlArea::getRandomArticle(){
|
||||||
|
|
||||||
|
//get file
|
||||||
|
zim::File file = this->get_file();
|
||||||
|
|
||||||
|
//create empty article
|
||||||
|
zim::Article article;
|
||||||
|
|
||||||
|
// do
|
||||||
|
// {
|
||||||
|
// generate random number
|
||||||
|
unsigned int seed = static_cast<unsigned int>(time(0));
|
||||||
|
zim::size_type idx = static_cast<zim::size_type>(static_cast<double>(file.getCountArticles()) * rand_r(&seed) / RAND_MAX);
|
||||||
|
|
||||||
|
//retrieve article
|
||||||
|
article = file.getArticle(idx);
|
||||||
|
|
||||||
|
//loop in case article is redirect
|
||||||
|
do
|
||||||
|
{
|
||||||
|
article = article.getRedirectArticle();
|
||||||
|
}while(article.isRedirect());
|
||||||
|
|
||||||
|
// }while(article.getUrl() == current_url);
|
||||||
|
|
||||||
|
return article;
|
||||||
|
}
|
||||||
|
|
||||||
|
zim::Article HtmlArea::getArticleFromUrl(QString url)
|
||||||
|
{
|
||||||
|
// TODO unescape url
|
||||||
|
|
||||||
|
//create ZIM file accessor
|
||||||
|
zim::File file = this->get_file();
|
||||||
|
|
||||||
|
//create empty article
|
||||||
|
zim::Article article;
|
||||||
|
|
||||||
|
// remove '+' signs
|
||||||
|
QString term = url.replace( '+', ' ');
|
||||||
|
|
||||||
|
//set default namespace
|
||||||
|
char ns = 'A';
|
||||||
|
|
||||||
|
//check for different namespace
|
||||||
|
if (term.contains("/"))
|
||||||
|
{
|
||||||
|
int index = term.indexOf("/");
|
||||||
|
if ( index == 1)
|
||||||
|
{
|
||||||
|
ns = term[0].toLatin1();
|
||||||
|
term.remove(0, 2);
|
||||||
|
}
|
||||||
|
//TODO what was this for?
|
||||||
|
/*
|
||||||
|
else
|
||||||
|
{
|
||||||
|
term.erase(1);
|
||||||
|
ns = term[0];
|
||||||
|
found2 = term.find("/");
|
||||||
|
term.erase(0, term.indexOf("/"));
|
||||||
|
}*/
|
||||||
|
}
|
||||||
|
|
||||||
|
// // // try to retrieve article
|
||||||
|
try
|
||||||
|
{
|
||||||
|
article = file.getArticle(ns, term.toStdString());
|
||||||
|
return article;
|
||||||
|
}
|
||||||
|
catch (const std::exception& e)
|
||||||
|
{
|
||||||
|
std::cerr << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
zim::Search::Results HtmlArea::searchArticleFromTitle(QString phrase)
|
||||||
|
{
|
||||||
|
char ns;
|
||||||
|
ns = 'A';
|
||||||
|
|
||||||
|
zim::File file = get_file();
|
||||||
|
|
||||||
|
zim::Article article;
|
||||||
|
|
||||||
|
zim::Search::Results result;
|
||||||
|
zim::Search search(file);
|
||||||
|
search.setSearchLimit(25);
|
||||||
|
search.find(result, ns, phrase.toStdString());
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// zim::Article HtmlArea::getArticleFromTitle(QString *phrase)
|
||||||
|
// {
|
||||||
|
// // historyCall = false;
|
||||||
|
// // screenblock(1);
|
||||||
|
//
|
||||||
|
// if( result.size() == 0)
|
||||||
|
// {
|
||||||
|
// // show_message("Error", "The article you requested (" + term + ") was not found.");
|
||||||
|
// // screenblock(0);
|
||||||
|
// return article;
|
||||||
|
// }else{
|
||||||
|
//
|
||||||
|
// if (result.size() == 1){
|
||||||
|
// log_debug("one article in result");
|
||||||
|
//
|
||||||
|
// article = z.getArticle(result[0].getArticle().getIndex());
|
||||||
|
//
|
||||||
|
// //loop in case article is redirect
|
||||||
|
// do
|
||||||
|
// {
|
||||||
|
// article = article.getRedirectArticle();
|
||||||
|
// }while(article.isRedirect());
|
||||||
|
//
|
||||||
|
// return article;
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// log_debug("more than one article in result");
|
||||||
|
// for (unsigned i = 0; i < result.size(); ++i)
|
||||||
|
// {
|
||||||
|
// res += "<li><a href='" + result[i].getArticle().getUrl() + "'>" + result[i].getArticle().getUrl() + "</a></li>";
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // fill_gtkhtml(res, url, title);
|
||||||
|
// }
|
||||||
|
// }
|
45
htmlarea.h
Normal file
45
htmlarea.h
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* Copyright (C) 2010 by Mirko Lindner *
|
||||||
|
* mirko@sharism.cc *
|
||||||
|
* *
|
||||||
|
* This program is free software; you can redistribute it and/or modify *
|
||||||
|
* it under the terms of the GNU General Public License as published by *
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or *
|
||||||
|
* (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This program is distributed in the hope that it will be useful, *
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||||
|
* GNU General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU General Public License *
|
||||||
|
* along with this program; if not, write to the *
|
||||||
|
* Free Software Foundation, Inc., *
|
||||||
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
#include <QTextBrowser>
|
||||||
|
#include <QWidget>
|
||||||
|
#include <zim/file.h>
|
||||||
|
#include <zim/search.h>
|
||||||
|
|
||||||
|
class HtmlArea : public QTextBrowser
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
HtmlArea(QWidget * parent = 0) : QTextBrowser(parent) {}
|
||||||
|
void searchArticle(QString term);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString *url;
|
||||||
|
zim::Article getArticleFromUrl(QString url);
|
||||||
|
zim::Search::Results searchArticleFromTitle(QString phrase);
|
||||||
|
zim::Article getRandomArticle();
|
||||||
|
const zim::File& get_file();
|
||||||
|
void setNewContent( int method, QString str );
|
||||||
|
|
||||||
|
public Q_SLOTS:
|
||||||
|
void linking( const QUrl &txt );
|
||||||
|
void getRandom();
|
||||||
|
};
|
21
main.cpp
Normal file
21
main.cpp
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#include <QApplication>
|
||||||
|
#include "qmain.h"
|
||||||
|
#include <cxxtools/loginit.h>
|
||||||
|
#include <cxxtools/log.h>
|
||||||
|
log_define("qvido.main")
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
log_init();
|
||||||
|
log_debug("launching with arguments" << argv[1] );
|
||||||
|
if (argc == 2)
|
||||||
|
{
|
||||||
|
QApplication app(argc, argv);
|
||||||
|
|
||||||
|
QMain QMain(argv[1]);
|
||||||
|
QMain.show();
|
||||||
|
return app.exec();
|
||||||
|
}else{
|
||||||
|
std::cout << "usage: " << argv[0] << " [PATH TO ZIM FILE]" << std::endl;
|
||||||
|
}
|
||||||
|
}
|
75
moc_htmlarea.cpp
Normal file
75
moc_htmlarea.cpp
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
** Meta object code from reading C++ file 'htmlarea.h'
|
||||||
|
**
|
||||||
|
** Created: Mon Mar 29 11:57:07 2010
|
||||||
|
** by: The Qt Meta Object Compiler version 61 (Qt 4.5.2)
|
||||||
|
**
|
||||||
|
** WARNING! All changes made in this file will be lost!
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
#include "htmlarea.h"
|
||||||
|
#if !defined(Q_MOC_OUTPUT_REVISION)
|
||||||
|
#error "The header file 'htmlarea.h' doesn't include <QObject>."
|
||||||
|
#elif Q_MOC_OUTPUT_REVISION != 61
|
||||||
|
#error "This file was generated using the moc from 4.5.2. It"
|
||||||
|
#error "cannot be used with the include files from this version of Qt."
|
||||||
|
#error "(The moc has changed too much.)"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
QT_BEGIN_MOC_NAMESPACE
|
||||||
|
static const uint qt_meta_data_HtmlArea[] = {
|
||||||
|
|
||||||
|
// content:
|
||||||
|
2, // revision
|
||||||
|
0, // classname
|
||||||
|
0, 0, // classinfo
|
||||||
|
2, 12, // methods
|
||||||
|
0, 0, // properties
|
||||||
|
0, 0, // enums/sets
|
||||||
|
0, 0, // constructors
|
||||||
|
|
||||||
|
// slots: signature, parameters, type, tag, flags
|
||||||
|
14, 10, 9, 9, 0x0a,
|
||||||
|
28, 9, 9, 9, 0x0a,
|
||||||
|
|
||||||
|
0 // eod
|
||||||
|
};
|
||||||
|
|
||||||
|
static const char qt_meta_stringdata_HtmlArea[] = {
|
||||||
|
"HtmlArea\0\0txt\0linking(QUrl)\0getRandom()\0"
|
||||||
|
};
|
||||||
|
|
||||||
|
const QMetaObject HtmlArea::staticMetaObject = {
|
||||||
|
{ &QTextBrowser::staticMetaObject, qt_meta_stringdata_HtmlArea,
|
||||||
|
qt_meta_data_HtmlArea, 0 }
|
||||||
|
};
|
||||||
|
|
||||||
|
const QMetaObject *HtmlArea::metaObject() const
|
||||||
|
{
|
||||||
|
return &staticMetaObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *HtmlArea::qt_metacast(const char *_clname)
|
||||||
|
{
|
||||||
|
if (!_clname) return 0;
|
||||||
|
if (!strcmp(_clname, qt_meta_stringdata_HtmlArea))
|
||||||
|
return static_cast<void*>(const_cast< HtmlArea*>(this));
|
||||||
|
return QTextBrowser::qt_metacast(_clname);
|
||||||
|
}
|
||||||
|
|
||||||
|
int HtmlArea::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
|
||||||
|
{
|
||||||
|
_id = QTextBrowser::qt_metacall(_c, _id, _a);
|
||||||
|
if (_id < 0)
|
||||||
|
return _id;
|
||||||
|
if (_c == QMetaObject::InvokeMetaMethod) {
|
||||||
|
switch (_id) {
|
||||||
|
case 0: linking((*reinterpret_cast< const QUrl(*)>(_a[1]))); break;
|
||||||
|
case 1: getRandom(); break;
|
||||||
|
default: ;
|
||||||
|
}
|
||||||
|
_id -= 2;
|
||||||
|
}
|
||||||
|
return _id;
|
||||||
|
}
|
||||||
|
QT_END_MOC_NAMESPACE
|
75
moc_qmain.cpp
Normal file
75
moc_qmain.cpp
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
** Meta object code from reading C++ file 'qmain.h'
|
||||||
|
**
|
||||||
|
** Created: Mon Mar 29 11:57:07 2010
|
||||||
|
** by: The Qt Meta Object Compiler version 61 (Qt 4.5.2)
|
||||||
|
**
|
||||||
|
** WARNING! All changes made in this file will be lost!
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
#include "qmain.h"
|
||||||
|
#if !defined(Q_MOC_OUTPUT_REVISION)
|
||||||
|
#error "The header file 'qmain.h' doesn't include <QObject>."
|
||||||
|
#elif Q_MOC_OUTPUT_REVISION != 61
|
||||||
|
#error "This file was generated using the moc from 4.5.2. It"
|
||||||
|
#error "cannot be used with the include files from this version of Qt."
|
||||||
|
#error "(The moc has changed too much.)"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
QT_BEGIN_MOC_NAMESPACE
|
||||||
|
static const uint qt_meta_data_QMain[] = {
|
||||||
|
|
||||||
|
// content:
|
||||||
|
2, // revision
|
||||||
|
0, // classname
|
||||||
|
0, 0, // classinfo
|
||||||
|
2, 12, // methods
|
||||||
|
0, 0, // properties
|
||||||
|
0, 0, // enums/sets
|
||||||
|
0, 0, // constructors
|
||||||
|
|
||||||
|
// slots: signature, parameters, type, tag, flags
|
||||||
|
7, 6, 6, 6, 0x08,
|
||||||
|
21, 6, 6, 6, 0x08,
|
||||||
|
|
||||||
|
0 // eod
|
||||||
|
};
|
||||||
|
|
||||||
|
static const char qt_meta_stringdata_QMain[] = {
|
||||||
|
"QMain\0\0displayHelp()\0searchDialog()\0"
|
||||||
|
};
|
||||||
|
|
||||||
|
const QMetaObject QMain::staticMetaObject = {
|
||||||
|
{ &QMainWindow::staticMetaObject, qt_meta_stringdata_QMain,
|
||||||
|
qt_meta_data_QMain, 0 }
|
||||||
|
};
|
||||||
|
|
||||||
|
const QMetaObject *QMain::metaObject() const
|
||||||
|
{
|
||||||
|
return &staticMetaObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *QMain::qt_metacast(const char *_clname)
|
||||||
|
{
|
||||||
|
if (!_clname) return 0;
|
||||||
|
if (!strcmp(_clname, qt_meta_stringdata_QMain))
|
||||||
|
return static_cast<void*>(const_cast< QMain*>(this));
|
||||||
|
return QMainWindow::qt_metacast(_clname);
|
||||||
|
}
|
||||||
|
|
||||||
|
int QMain::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
|
||||||
|
{
|
||||||
|
_id = QMainWindow::qt_metacall(_c, _id, _a);
|
||||||
|
if (_id < 0)
|
||||||
|
return _id;
|
||||||
|
if (_c == QMetaObject::InvokeMetaMethod) {
|
||||||
|
switch (_id) {
|
||||||
|
case 0: displayHelp(); break;
|
||||||
|
case 1: searchDialog(); break;
|
||||||
|
default: ;
|
||||||
|
}
|
||||||
|
_id -= 2;
|
||||||
|
}
|
||||||
|
return _id;
|
||||||
|
}
|
||||||
|
QT_END_MOC_NAMESPACE
|
94
qmain.cpp
Normal file
94
qmain.cpp
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* Copyright (C) 2010 by Mirko Lindner *
|
||||||
|
* mirko@sharism.cc *
|
||||||
|
* *
|
||||||
|
* This program is free software; you can redistribute it and/or modify *
|
||||||
|
* it under the terms of the GNU General Public License as published by *
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or *
|
||||||
|
* (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This program is distributed in the hope that it will be useful, *
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||||
|
* GNU General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU General Public License *
|
||||||
|
* along with this program; if not, write to the *
|
||||||
|
* Free Software Foundation, Inc., *
|
||||||
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
#include <QtGui>
|
||||||
|
#include <QWidget>
|
||||||
|
#include <QMessageBox>
|
||||||
|
#include "qmain.h"
|
||||||
|
|
||||||
|
QMain::QMain(std::string File)
|
||||||
|
{
|
||||||
|
|
||||||
|
this->resize(320, 240);
|
||||||
|
|
||||||
|
fileLocation = File;
|
||||||
|
|
||||||
|
centralWidget = new HtmlArea(this);
|
||||||
|
setCentralWidget(centralWidget);
|
||||||
|
|
||||||
|
centralWidget->getRandom();
|
||||||
|
registerCommands();
|
||||||
|
QObject::connect(centralWidget,SIGNAL(anchorClicked(const QUrl &)),
|
||||||
|
centralWidget,SLOT(linking(const QUrl&)));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void QMain::searchDialog(){
|
||||||
|
bool ok;
|
||||||
|
QString text = QInputDialog::getText(this, tr("Search Article"),
|
||||||
|
tr("Article Title"), QLineEdit::Normal,
|
||||||
|
"", &ok);
|
||||||
|
if (ok && !text.isEmpty())
|
||||||
|
this->centralWidget->searchArticle(text);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void QMain::registerCommands()
|
||||||
|
{
|
||||||
|
//get random article
|
||||||
|
randomArticleAct = new QAction(tr("Load &Random Article"), this);
|
||||||
|
randomArticleAct->setShortcut(tr("Ctrl+R"));
|
||||||
|
randomArticleAct->setStatusTip(tr("Random Article"));
|
||||||
|
connect(randomArticleAct, SIGNAL(triggered()), this->centralWidget, SLOT(getRandom()));
|
||||||
|
this->addAction(randomArticleAct);
|
||||||
|
|
||||||
|
//get search dialog
|
||||||
|
searchArticleAct = new QAction(tr("&Search Dialog"), this);
|
||||||
|
searchArticleAct->setShortcut(tr("Ctrl+S"));
|
||||||
|
searchArticleAct->setStatusTip(tr("Search for Article"));
|
||||||
|
connect(searchArticleAct, SIGNAL(triggered()), this, SLOT(searchDialog()));
|
||||||
|
this->addAction(searchArticleAct);
|
||||||
|
|
||||||
|
//display help
|
||||||
|
displayHelpAct = new QAction(tr("Display &H"), this);
|
||||||
|
displayHelpAct->setShortcut(tr("F1"));
|
||||||
|
displayHelpAct->setStatusTip(tr("Display Help"));
|
||||||
|
connect(displayHelpAct, SIGNAL(triggered()), this, SLOT(displayHelp()));
|
||||||
|
this->addAction(displayHelpAct);
|
||||||
|
}
|
||||||
|
|
||||||
|
void QMain::displayHelp(){
|
||||||
|
QString txt = "Usage: \n";
|
||||||
|
txt.append("Ctrl + R = Display random article\n");
|
||||||
|
txt.append("Ctrl + S = Search for article\n");
|
||||||
|
txt.append("Ctrl + T = Go to articles top\n");
|
||||||
|
txt.append("Tab = Rotate through links\n");
|
||||||
|
txt.append("Enter = Activate link\n");
|
||||||
|
txt.append("Ctrl + H = Display history\n");
|
||||||
|
txt.append("Ctrl + B = Go back in history\n");
|
||||||
|
txt.append("Ctrl + F = Go forward in history\n");
|
||||||
|
txt.append("Ctrl + Q = Quit Vido\n");
|
||||||
|
txt.append("F1 = Display this help\n");
|
||||||
|
|
||||||
|
QMessageBox::information(this, "Help",
|
||||||
|
txt,
|
||||||
|
QMessageBox::Close);
|
||||||
|
|
||||||
|
}
|
49
qmain.h
Normal file
49
qmain.h
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* Copyright (C) 2010 by Mirko Lindner *
|
||||||
|
* mirko@sharism.cc *
|
||||||
|
* *
|
||||||
|
* This program is free software; you can redistribute it and/or modify *
|
||||||
|
* it under the terms of the GNU General Public License as published by *
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or *
|
||||||
|
* (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This program is distributed in the hope that it will be useful, *
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||||
|
* GNU General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU General Public License *
|
||||||
|
* along with this program; if not, write to the *
|
||||||
|
* Free Software Foundation, Inc., *
|
||||||
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
#ifndef QMAIN_H
|
||||||
|
#define QMAIN_H
|
||||||
|
|
||||||
|
#include <QMainWindow>
|
||||||
|
#include <string>
|
||||||
|
#include "htmlarea.h"
|
||||||
|
|
||||||
|
|
||||||
|
class QMain : public QMainWindow
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
QMain(std::string);
|
||||||
|
std::string fileLocation;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void registerCommands();
|
||||||
|
HtmlArea *centralWidget;
|
||||||
|
QAction *randomArticleAct;
|
||||||
|
QAction *searchArticleAct;
|
||||||
|
QAction *displayHelpAct;
|
||||||
|
|
||||||
|
private Q_SLOTS:
|
||||||
|
void displayHelp();
|
||||||
|
void searchDialog();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
14
qvido.pro
Normal file
14
qvido.pro
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
######################################################################
|
||||||
|
# Automatically generated by qmake (2.01a) Sat Mar 27 14:19:19 2010
|
||||||
|
######################################################################
|
||||||
|
|
||||||
|
TEMPLATE = app
|
||||||
|
TARGET =
|
||||||
|
DEPENDPATH += .
|
||||||
|
INCLUDEPATH += . /usr/include
|
||||||
|
LIBS = -L/usr/local/lib -lzim -lcxxtools
|
||||||
|
; CONFIG = warn_on
|
||||||
|
|
||||||
|
# Input
|
||||||
|
SOURCES += main.cpp htmlarea.cpp qmain.cpp
|
||||||
|
HEADERS += htmlarea.h qmain.h
|
Loading…
Reference in New Issue
Block a user