1
0
mirror of git://projects.qi-hardware.com/vido.git synced 2024-12-22 19:59:52 +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; Widget *html;
GtkWidget *html_wg; GtkWidget *html_wg;
static zim::File zimFile;
static bool initialized = false;
// // // misc functions // // // 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 // // copy article html from while loop into global variable
void set_article(std::string txt) void set_article(std::string txt)
{ {
@ -62,8 +78,12 @@ void set_article(std::string txt)
// // display random article // // display random article
void show_random(){ void show_random(){
std::cout<<"random called"<<".\n";
zim::File m = get_file();
std::cout<<"random got file"<<".\n";
while(true){ 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::size_type idx = static_cast<zim::size_type>(static_cast<double>(m.getCountArticles()) * rand_r(&seed) / RAND_MAX);
zim::Article article = m.getArticle(idx); zim::Article article = m.getArticle(idx);
@ -92,7 +112,7 @@ void search_window(main_window *window_x){
void set_html(const gchar *url){ void set_html(const gchar *url){
// // create ZIM file accessor // // create ZIM file accessor
zim::File m(file); zim::File m = get_file();
// // convert url to string // // convert url to string
std::string term; std::string term;
@ -156,7 +176,7 @@ void set_html(const gchar *url){
// // test functions // // test functions
void set_search(const gchar *url){ void set_search(const gchar *url){
// std::cout<<"url"<<url<<"."; // std::cout<<"url"<<url<<".";
zim::File z(file); zim::File z = get_file();
zim::Search::Results result; zim::Search::Results result;
result.clear(); result.clear();
@ -208,7 +228,7 @@ void articles2file(){
std::ofstream myfile; std::ofstream myfile;
myfile.open ("articles.txt"); 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) for (zim::File::const_iterator it = f.begin(); it != f.end(); ++it)
{ {
myfile << it->getUrl() << '\n'; myfile << it->getUrl() << '\n';
@ -235,16 +255,19 @@ bool on_link_clicked(GtkHTML *html, const gchar *url)
// // main function // // main function
int main(int argc, char **argv) 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; main_window window;
window.set_title("Vido"); window.set_title("Vido");
window.set_border_width(0); // window.set_border_width(0);
window.set_default_size(320, 240); window.set_default_size(320, 240);
// window.set_resizable(0); // window.set_resizable(0);
html_wg = gtk_html_new(); html_wg = gtk_html_new();
@ -262,9 +285,14 @@ int main(int argc, char **argv)
window.show_all(); window.show_all();
show_random(); show_random();
// articles2file(); // articles2file();
// set_berlin(); // set_berlin();
Main::run(window); 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; return 0;
} }