mirror of
git://projects.qi-hardware.com/vido.git
synced 2024-12-22 14:13:21 +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:
parent
046bb78668
commit
e161d10e62
88
src/vido.cc
88
src/vido.cc
@ -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,36 +255,44 @@ 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;
|
||||||
|
window.set_title("Vido");
|
||||||
|
// window.set_border_width(0);
|
||||||
|
window.set_default_size(320, 240);
|
||||||
|
// window.set_resizable(0);
|
||||||
|
|
||||||
main_window window;
|
html_wg = gtk_html_new();
|
||||||
window.set_title("Vido");
|
|
||||||
window.set_border_width(0);
|
html = Glib::wrap(html_wg);
|
||||||
window.set_default_size(320, 240);
|
g_signal_connect( G_OBJECT( html_wg ), "link_clicked", G_CALLBACK( on_link_clicked ), NULL );
|
||||||
// window.set_resizable(0);
|
gtk_html_set_caret_mode(GTK_HTML(html_wg),true);
|
||||||
|
|
||||||
html_wg = gtk_html_new();
|
|
||||||
|
ScrolledWindow scrolled_window;
|
||||||
html = Glib::wrap(html_wg);
|
|
||||||
g_signal_connect( G_OBJECT( html_wg ), "link_clicked", G_CALLBACK( on_link_clicked ), NULL );
|
scrolled_window.add(*html);
|
||||||
gtk_html_set_caret_mode(GTK_HTML(html_wg),true);
|
scrolled_window.set_policy(POLICY_NEVER, POLICY_AUTOMATIC);
|
||||||
|
|
||||||
|
window.add(scrolled_window);
|
||||||
ScrolledWindow scrolled_window;
|
window.show_all();
|
||||||
|
|
||||||
scrolled_window.add(*html);
|
show_random();
|
||||||
scrolled_window.set_policy(POLICY_NEVER, POLICY_AUTOMATIC);
|
// articles2file();
|
||||||
|
// set_berlin();
|
||||||
window.add(scrolled_window);
|
Main::run(window);
|
||||||
window.show_all();
|
}else{
|
||||||
|
std::cout<<"You provided too many or too few arguments("<< argc <<").\n";
|
||||||
show_random();
|
std::cout<<"Vido is to be used as follows:"<<".\n";
|
||||||
// articles2file();
|
std::cout<<"vido [PATH TO ZIM FILE]"<<".\n";
|
||||||
// set_berlin();
|
}
|
||||||
Main::run(window);
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user