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

load file only once; check for argument count, if not 2 show message

Signed-off-by: Mirko Lindner <mirko@qi-hardware.com>
This commit is contained in:
Mirko Lindner 2009-12-20 20:12:23 +01:00
parent 046bb78668
commit e161d10e62

View File

@ -49,8 +49,24 @@ Window *window;
Widget *html;
GtkWidget *html_wg;
static zim::File zimFile;
static bool initialized = false;
// // // misc functions
const zim::File get_file()
{
if (!initialized){
std::cout<<"file not initialized :"<<file<<".\n";
zim::File zimFile(file);
initialized = true;
}else{
std::cout<<"file initialized :"<<file<<".\n";
}
std::cout<<"returning file"<<".\n";
return zimFile;
}
// // copy article html from while loop into global variable
void set_article(std::string txt)
{
@ -62,8 +78,12 @@ void set_article(std::string txt)
// // display random article
void show_random(){
std::cout<<"random called"<<".\n";
zim::File m = get_file();
std::cout<<"random got file"<<".\n";
while(true){
zim::File m(file);
std::cout<<"random running loop"<<".\n";
zim::size_type idx = static_cast<zim::size_type>(static_cast<double>(m.getCountArticles()) * rand_r(&seed) / RAND_MAX);
zim::Article article = m.getArticle(idx);
@ -92,7 +112,7 @@ void search_window(main_window *window_x){
void set_html(const gchar *url){
// // create ZIM file accessor
zim::File m(file);
zim::File m = get_file();
// // convert url to string
std::string term;
@ -156,7 +176,7 @@ void set_html(const gchar *url){
// // test functions
void set_search(const gchar *url){
// std::cout<<"url"<<url<<".";
zim::File z(file);
zim::File z = get_file();
zim::Search::Results result;
result.clear();
@ -208,7 +228,7 @@ void articles2file(){
std::ofstream myfile;
myfile.open ("articles.txt");
zim::File f(file);
zim::File f = get_file();
for (zim::File::const_iterator it = f.begin(); it != f.end(); ++it)
{
myfile << it->getUrl() << '\n';
@ -235,36 +255,44 @@ bool on_link_clicked(GtkHTML *html, const gchar *url)
// // main function
int main(int argc, char **argv)
{
if (argc == 2)
{
file = argv[1];
file = argv[1];
std::cout<<"vido is here file:"<<file<<".\n";
Main kit(argc, argv);
Main kit(argc, argv);
main_window window;
window.set_title("Vido");
// window.set_border_width(0);
window.set_default_size(320, 240);
// window.set_resizable(0);
main_window window;
window.set_title("Vido");
window.set_border_width(0);
window.set_default_size(320, 240);
// window.set_resizable(0);
html_wg = gtk_html_new();
html = Glib::wrap(html_wg);
g_signal_connect( G_OBJECT( html_wg ), "link_clicked", G_CALLBACK( on_link_clicked ), NULL );
gtk_html_set_caret_mode(GTK_HTML(html_wg),true);
html_wg = gtk_html_new();
html = Glib::wrap(html_wg);
g_signal_connect( G_OBJECT( html_wg ), "link_clicked", G_CALLBACK( on_link_clicked ), NULL );
gtk_html_set_caret_mode(GTK_HTML(html_wg),true);
ScrolledWindow scrolled_window;
scrolled_window.add(*html);
scrolled_window.set_policy(POLICY_NEVER, POLICY_AUTOMATIC);
window.add(scrolled_window);
window.show_all();
show_random();
// articles2file();
// set_berlin();
Main::run(window);
ScrolledWindow scrolled_window;
scrolled_window.add(*html);
scrolled_window.set_policy(POLICY_NEVER, POLICY_AUTOMATIC);
window.add(scrolled_window);
window.show_all();
show_random();
// articles2file();
// set_berlin();
Main::run(window);
}else{
std::cout<<"You provided too many or too few arguments("<< argc <<").\n";
std::cout<<"Vido is to be used as follows:"<<".\n";
std::cout<<"vido [PATH TO ZIM FILE]"<<".\n";
}
return 0;
}