GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Sat Aug 27, 2016 9:51 am

All times are UTC

Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: how to create an info message for the user
PostPosted: Mon Feb 10, 2014 6:21 pm 

Joined: Mon Feb 10, 2014 10:31 am
Posts: 3
int main(int argc, char **argv){
        fputs("libgcrypt min version required: 1.5.0\n", stderr);
        return -1;
    gcry_control(GCRYCTL_INIT_SECMEM, 16384, 0);

    const gchar *ret = glib_check_version(2, 36, 0);
    if(ret != NULL){
        printf("%s\n", ret);
        return -1;

    setlocale(LC_ALL, "");
    bindtextdomain(PACKAGE, LOCALE_DIR);

    GtkApplication *app;
    int status;
    GError *err = NULL;
    GdkPixbuf *logo = gdk_pixbuf_new_from_file(icon, &err);

    app = gtk_application_new ("org.gtk.example",G_APPLICATION_FLAGS_NONE);
    g_signal_connect (app, "startup", G_CALLBACK (startup), NULL);
    g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
    status = g_application_run (G_APPLICATION (app), argc, argv);
    g_object_unref (app);
    return status;

The function startup creates a g_menu with 2 entries while the function activate create the window, the grid and 2 buttons (encrypt, decrypt). When the "encrypt" button is clicked the function do_enc is called. Inside this function a dialog with 2 gtk_entry (type pwd and retype pwd) and 2 buttons (close and ok) is created.

My problem is that the encryption can take long time if the file is very large so I need to give the user an info (like "hey, wait some minutes"). I thought to use a gtk_message_dialog_new or a gtk_info_bar_new but I am not able to show them because the function gtk_widget_show does nothing outside the main xD

I saw that there are g_timeout_add and g_idle_add that could be used to call from inside the main the function but I have no idea about how to use them (and honestly I think that it isn't a good idea to continuously call the function do_enc)..
So I don't know how to show this info message. Any idea?

Last edited by zerohour on Sat Mar 01, 2014 5:26 pm, edited 1 time in total.
Lack of paragraphs

 Post subject: Re: how to create an info message for the user
PostPosted: Tue Feb 11, 2014 7:22 am 
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 1048
Location: UK

I would have anything that would take a long time and lock the user interface done in a separate thread. The worker thread would then do the file encryption passing information on its progress via some type of communication to the main thread. The main thread can display a dialog message possible with a progress bar. This way the main thread is still able to redraw the windows if needed so that it does not appear frozen to the user. You will need some way for the threads to communicate the progress and when the thread has finished. This could be via a global variable using Mutexs and a timer in the main thread, pipes or some other method.


 Post subject: Re: how to create an info message for the user
PostPosted: Wed Feb 12, 2014 8:29 am 

Joined: Mon Feb 10, 2014 10:31 am
Posts: 3
So you're tell me to do something like:

int main:
//g_app creation
//g_signal startup
//g_signal activate

//create mainwin
//create 2 buttons
//g_signal button-enc
//g_signal button-dec

//g_thread for encryption

//g_thread for decryption

Is this right?

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC

Who is online

Users browsing this forum: Google Adsense [Bot], Yahoo [Bot] and 3 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group