1
0
mirror of git://projects.qi-hardware.com/vido.git synced 2024-12-22 19:28:59 +02:00

implement help function

Signed-off-by: Mirko Lindner <mirko@sharism.cc>
This commit is contained in:
Mirko Lindner 2010-02-20 20:45:52 +01:00
parent 9a3ad4954d
commit e7a817a3c7

View File

@ -44,18 +44,25 @@ extern "C" {
// std::string content; // std::string content;
std::string fileName; std::string fileName;
main_window *window; //TODO this can't be right
main_window *window2;
Gtk::ScrolledWindow *scrolled_window2;
Gtk::Widget *html; Gtk::Widget *html;
GtkWidget *html_wg; GtkWidget *html_wg;
std::vector < std::pair< std::string, std::string > > history; std::vector < std::pair< std::string, std::string > > history;
unsigned int position = 0; unsigned int position = 0;
bool historyCall = false; bool historyCall = false;
// variable to keep url of currently displayed article
std::string current_url = "";
// // // misc functions // // // misc functions
// get zimFile, if not already opened, open file // get zimFile, if not already opened, open file
const zim::File& get_file() const zim::File& get_file()
{ {
static zim::File zimFile; static zim::File zimFile;
if (!zimFile.good()) if (!zimFile.good())
{ {
log_debug("file not initialized:" << fileName); log_debug("file not initialized:" << fileName);
@ -70,18 +77,36 @@ const zim::File& get_file()
// display message in gtk window // display message in gtk window
void show_message(std::string title, std::string txt) void show_message(std::string title, std::string txt)
{ {
message_dialog(window, title, txt); message_dialog(window2, title, txt);
}
void show_help()
{
log_debug("displaying help");
std::string title = "Help";
std::string txt = "Usage: \n";
txt += "Ctrl + R = Display random article\n";
txt += "Ctrl + S = Search for article\n";
txt += "Ctrl + T = Go to articles top\n";
txt += "Tab = Rotate through links\n";
txt += "Enter = Activate link\n";
txt += "Ctrl + H = Display history\n";
txt += "Ctrl + B = Go back in history\n";
txt += "Ctrl + F = Go forward in history\n";
txt += "Ctrl + Q = Quit Vido\n";
txt += "F1 = Display this help\n";
show_message(title, txt);
} }
// fill gtkhtml widget with new content // fill gtkhtml widget with new content
//TODO prepend "top" anchor on html
void fill_gtkhtml(std::string& html, std::string url, std::string title){ void fill_gtkhtml(std::string& html, std::string url, std::string title){
log_debug("fill gtkhtml called with " << url << " and " << title); log_debug("fill gtkhtml called with " << url << " and " << title);
std::string ccontent; std::string ccontent;
ccontent = "<a name=\"top\"></a>" + html; ccontent = "<a name=\"top\"></a>" + html;
gtk_html_flush(GTK_HTML(html_wg)); gtk_html_flush(GTK_HTML(html_wg));
gtk_html_load_from_string(GTK_HTML(html_wg), ccontent.c_str(), -1); gtk_html_load_from_string(GTK_HTML(html_wg), ccontent.c_str(), -1);
current_url = url;
if ((url != "") && title != ""){ if ((url != "") && title != ""){
if (position == 0){ if (position == 0){
log_debug("adding " << title << " to history"); log_debug("adding " << title << " to history");
@ -102,6 +127,11 @@ void fill_gtkhtml(std::string& html, std::string url, std::string title){
} }
} }
// gtk_html_get_selection_html(GTK_HTML(html_wg), )
while( Gtk::Main::events_pending() ){
Gtk::Main::iteration();
}
window2->connect_all();
} }
@ -162,13 +192,14 @@ void history_jump(int jumper){
// // display random article // // display random article
void show_random() void show_random()
{ {
// window2->disconnect_all();
log_debug("random called."); log_debug("random called. window all disconnected");
zim::File m = get_file(); zim::File m = get_file();
zim::Article article;
do
{
unsigned int seed = static_cast<unsigned int>(time(0)); unsigned int seed = static_cast<unsigned int>(time(0));
zim::size_type idx = static_cast<zim::size_type>(static_cast<double>(m.getCountArticles()) * rand_r(&seed) / RAND_MAX); zim::size_type idx = static_cast<zim::size_type>(static_cast<double>(m.getCountArticles()) * rand_r(&seed) / RAND_MAX);
zim::Article article;
article = m.getArticle(idx); article = m.getArticle(idx);
@ -178,6 +209,8 @@ void show_random()
article = article.getRedirectArticle(); article = article.getRedirectArticle();
}while(article.isRedirect()); }while(article.isRedirect());
}while(article.getUrl() == current_url);
std::string res = article.getPage(); std::string res = article.getPage();
log_debug("article size=" << res.size()); log_debug("article size=" << res.size());
@ -185,11 +218,14 @@ void show_random()
log_debug("article namespace=" << article.getNamespace()); log_debug("article namespace=" << article.getNamespace());
position = 0; position = 0;
fill_gtkhtml(res, article.getUrl(), article.getTitle()); fill_gtkhtml(res, article.getUrl(), article.getTitle());
log_debug("random called. window all connected");
} }
// // display search dialog // // display search dialog
void search_window(main_window *window_x) void search_window(main_window *window_x)
{ {
// html_color = html_color_new_from_rgb('255','0','0');
// gtk_html_set_color(GTK_HTML(html_wg),html_color);
search_dialog(window_x, " "); search_dialog(window_x, " ");
} }
@ -247,11 +283,11 @@ void getArticleFromUrl(const gchar *url, int pos = 0)
// // try to retrieve article // // try to retrieve article
try try
{ {
#if HAVE_ZIM_QUNICODE_H // #if HAVE_ZIM_QUNICODE_H
zim::Article article = m.getArticle(ns, zim::QUnicodeString(term)); // zim::Article article = m.getArticle(ns, zim::QUnicodeString(term));
#else // #else
zim::Article article = m.getArticle(ns, term); zim::Article article = m.getArticle(ns, term);
#endif // #endif
if (article.good()) // check if article is really found if (article.good()) // check if article is really found
{ {
@ -314,11 +350,11 @@ void getArticleFromTitle(const gchar *phrase)
log_debug("more than one article in result"); log_debug("more than one article in result");
for (unsigned i = 0; i < result.size(); ++i) for (unsigned i = 0; i < result.size(); ++i)
{ {
#if HAVE_ZIM_QUNICODE_H // #if HAVE_ZIM_QUNICODE_H
res += "<li><a href=" + result[i].getArticle().getLongUrl().toXML() + ">" + result[i].getArticle().getLongUrl().toXML() + "</a></li>"; // res += "<li><a href=" + result[i].getArticle().getLongUrl().toXML() + ">" + result[i].getArticle().getLongUrl().toXML() + "</a></li>";
#else // #else
res += "<li><a href='" + result[i].getArticle().getUrl() + "'>" + result[i].getArticle().getUrl() + "</a></li>"; res += "<li><a href='" + result[i].getArticle().getUrl() + "'>" + result[i].getArticle().getUrl() + "</a></li>";
#endif // #endif
} }
url = ""; url = "";
title = ""; title = "";
@ -385,15 +421,16 @@ int main(int argc, char **argv)
// window.set_border_width(0); // window.set_border_width(0);
window.set_default_size(220, 240); window.set_default_size(220, 240);
// window.set_resizable(0); // window.set_resizable(0);
window.connect_all();
html_wg = gtk_html_new(); html_wg = gtk_html_new();
window2 = &window;
html = Glib::wrap(html_wg); html = Glib::wrap(html_wg);
g_signal_connect( G_OBJECT( html_wg ), "link_clicked", G_CALLBACK( on_link_clicked ), NULL ); g_signal_connect( G_OBJECT( html_wg ), "link_clicked", G_CALLBACK( on_link_clicked ), NULL );
g_signal_connect( G_OBJECT( html_wg ), "scroll", G_CALLBACK( scrolled ), NULL ); g_signal_connect( G_OBJECT( html_wg ), "scroll", G_CALLBACK( scrolled ), NULL );
gtk_html_set_caret_mode(GTK_HTML(html_wg),false); gtk_html_set_caret_mode(GTK_HTML(html_wg),false);
// gtk_html_adjust_cursor_position(GTK_HTML(html_wg)); // gtk_html_adjust_cursor_position(GTK_HTML(html_wg));
static Gtk::ScrolledWindow scrolled_window; Gtk::ScrolledWindow scrolled_window;
scrolled_window2 = &scrolled_window;
scrolled_window.add(*html); scrolled_window.add(*html);
scrolled_window.set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC); scrolled_window.set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);