Re: Opening dialogs outside the Gtk thread?



For a better understanding of my problem, please have a look at this function, which is called from a thread running parallel to the thread owning the Gtk lock:
(Please notice the comments!!)

/// Handles a file overwrite request encountered during a transfer.
int TransferDirector::handle_status_overwrite(
    const Gnome::Vfs::Transfer::ProgressInfo& info)
{
    using namespace Gnome::Vfs;

    // hide the transfer dialog
    // Please note that NO calls to gdk_threads_* are needed!!
    // I have NO idea why; it just works
    dialog_->hide();

    // create the message dialog
    TransferOverwriteDialog dlg(
	get_local_path_from_uri(info.get_target_name()));

    // Please note that here the two calls ARE NEEDED!
    // If I leave them out, the program will lock up
    gdk_threads_enter();
    int response = dlg.run();
    gdk_threads_leave();

    OverwriteAction action;

    switch (response)
    {
    case TransferOverwriteDialog::RESPONSE_REPLACE:
	action = dlg.is_remember_choice()
	    ? XFER_OVERWRITE_ACTION_REPLACE_ALL
	    : XFER_OVERWRITE_ACTION_REPLACE;
	break;
    case TransferOverwriteDialog::RESPONSE_SKIP:
	action = dlg.is_remember_choice()
	    ? XFER_OVERWRITE_ACTION_SKIP_ALL
	    : XFER_OVERWRITE_ACTION_SKIP;
	if (info.get_total_files() == 1)
	    completion_scheduled_ = true;
	break;
    case TransferOverwriteDialog::RESPONSE_CANCEL:
	action = XFER_OVERWRITE_ACTION_ABORT;
	if (info.get_total_files() == 1)
	    completion_scheduled_ = true;
	else
	    cancellation_scheduled_ = true;
	break;
    default:
	assert(false);
    }

    // show the transfer dialog again
    // AGAIN, the two calls are NOT needed!
    dialog_->show();

    return action;
}


I think this function pretty much shows why I think I do not know the whole story; it just doesn't make any sense to me that I need to lock Gtk for the one dialog, but not for the other. The only differences between the two dialogs are that one is non-modal and has been created (but not displayed!) in the main thread, while the other one is modal and has been created in place (see code).

Sorry, but I'm really lost here, any clarification on the behavior of Gtk+ in these situations much appreciated.

Regards,
Matthias




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]