Cannot send a notifications onto a gnome desktop environment, what do I wrong.
- From: eddie <mrcyberfighter gmail com>
- To: gtk-app-devel-list gnome org
- Subject: Cannot send a notifications onto a gnome desktop environment, what do I wrong.
- Date: Tue, 6 Dec 2016 20:01:57 +0100
Hi everybody,
I have write the following code but their is no way to send a
notification even
if it's say that isn't guarantee that something will happen in the
documentation
concerning notifications with gtk/gio.
```C
#include <gtk/gtk.h>
#include <stdlib.h>
#include <string.h>
#define DEBUG_FUNC_MARK do { fprintf(stdout,"\n%s(...) called\n",
__func__) ; } while(0) ;
/** GtkApplication example:
*
* To compile with:
*
* $ cc gtk_GtkApplication.c `pkg-config --cflags --libs gtk+-3.0`
*
*****************************************************************/
static void activate (GApplication *application, gpointer user_data) ;
static void startup(GApplication *application, gpointer user_data) ;
static void open_files(GApplication *application, GFile **files, gint
n_files, const gchar *hint) ;
static void about_activated(GSimpleAction *action, GVariant *parameter,
gpointer app) ;
static void preferences_activated(GSimpleAction *action, GVariant
*parameter, gpointer app) ;
static void quit_activated(GSimpleAction *action, GVariant *parameter,
gpointer app) ;
static void shutdown_app(GApplication *application, gpointer user_data) ;
void destroy(GtkWidget *widget, gpointer pointer) ;
static gboolean delete_event(GtkWidget *widget,GdkEvent *event,gpointer
pointer) ;
GtkApplication *app;
int main (int argc, char **argv) {
int status;
GtkWidget *window ;
// Given the program a name to displaying to the user through:
g_get_application_name().
g_set_application_name("myapp") ;
const char *app_id = "myapp.org" ;
if ( ! g_application_id_is_valid(app_id) ) {
fprintf(stderr, "Wrong app id\n") ;
exit(EXIT_FAILURE) ;
}
// Setting the applications flags
int app_flags = G_APPLICATION_HANDLES_OPEN ;
app_flags |= G_APPLICATION_NON_UNIQUE ;
app_flags |= G_APPLICATION_SEND_ENVIRONMENT ;
app = gtk_application_new(app_id, (GApplicationFlags) app_flags) ;
// The ::activate signal is emitted on the primary instance when an
activation occurs. When g_application_activate() is called.
g_signal_connect( G_APPLICATION(app), "activate",
G_CALLBACK(activate), NULL) ;
// The ::open signal is emitted on the primary instance when there
are files to open.
g_signal_connect( G_APPLICATION(app), "open",
G_CALLBACK(open_files), NULL) ;
// The ::startup signal is emitted on the primary instance
immediately after registration. When g_application_register() is called.
g_signal_connect( G_APPLICATION(app), "startup",
G_CALLBACK(startup), NULL) ;
// The ::shutdown signal is emitted only on the registered primary
instance immediately after the main loop terminates.
g_signal_connect( G_APPLICATION(app), "shutdown",
G_CALLBACK(shutdown_app), NULL) ;
GError *err = NULL ;
g_application_register(G_APPLICATION(app), NULL, &err) ;
if (err != NULL) {
fprintf(stderr,"Cannot register app: %s\n", err->message) ;
exit(EXIT_FAILURE) ;
}
fprintf(stdout,"GtkApplication DBUS path: %s\n",
g_application_get_dbus_object_path(G_APPLICATION(app)) ) ;
GtkBuilder *builder;
GMenuModel *app_menu ;
static GActionEntry app_entries[] = {
{ "preferences", preferences_activated, NULL, NULL, NULL },
{ "about", about_activated, NULL, NULL, NULL },
{ "quit", quit_activated, NULL, NULL, NULL }
};
g_action_map_add_action_entries(G_ACTION_MAP(app), app_entries,
G_N_ELEMENTS(app_entries), app);
builder = gtk_builder_new_from_file("./GtkApplication/menus.ui");
fprintf(stdout,"builder: %p\n", builder) ;
app_menu = G_MENU_MODEL (gtk_builder_get_object (builder, "appmenu"));
if (gtk_application_prefers_app_menu(app)) {
gtk_application_set_app_menu(GTK_APPLICATION(app), app_menu);
}
g_object_unref (builder);
//g_application_set_inactivity_timeout( G_APPLICATION(app), 10000) ;
window = gtk_application_window_new(app) ;
g_signal_connect(G_OBJECT(window),"destroy",G_CALLBACK(destroy),NULL) ;
g_signal_connect(G_OBJECT(window),"delete-event",G_CALLBACK(delete_event),NULL)
;
gtk_widget_show_all(window) ;
g_application_set_default(g_application_get_default()) ;
g_application_activate(G_APPLICATION(app)) ;
status = g_application_run(G_APPLICATION(app), argc, argv) ;
g_object_unref (app);
return status;
}
static void activate(GApplication *application, gpointer user_data) {
#ifdef DEBUG
DEBUG_FUNC_MARK
#endif
g_application_hold(application) ;
GNotification *notification = g_notification_new(
g_get_application_name() ) ;
g_notification_set_title(notification, "title") ;
g_notification_set_default_action(notification, "app.actions") ;
gchar *notification_body = g_strdup_printf("Test notification body\n") ;
g_notification_set_body(notification, notification_body) ;
g_notification_set_priority(notification,
G_NOTIFICATION_PRIORITY_NORMAL) ;
g_application_send_notification( G_APPLICATION(application),
"notification", notification);
g_application_release(application) ;
/** @Note: when doing a longer-lasting action here that returns
** to the mainloop, you should use g_application_hold() and
** g_application_release() to keep the application alive until
** the action is completed.
** Only by not intern done things like file opening not by toplevel
displaying .
********************************************************************************/
}
static void startup(GApplication *application, gpointer user_data) {
//#ifdef DEBUG
DEBUG_FUNC_MARK
//#endif
g_print ("startup\n");
/** @Note: when doing a longer-lasting action here that returns
** to the mainloop, you should use g_application_hold() and
** g_application_release() to keep the application alive until
** the action is completed.
** Only by not intern done things like file opening not by toplevel
displaying .
********************************************************************************/
}
static void open_files(GApplication *application, GFile **files, gint
n_files, const gchar *hint) {
//#ifdef DEBUG
DEBUG_FUNC_MARK
//#endif
gint i;
for (i = 0; i < n_files; i++) {
gchar *uri = g_file_get_uri (files[i]);
g_print ("open %s\n", uri);
g_free (uri);
}
/** @Note: when doing a longer-lasting action here that returns
** to the mainloop, you should use g_application_hold() and
** g_application_release() to keep the application alive until
** the action is completed.
** Only by not intern done things like file opening not by toplevel
displaying .
********************************************************************************/
}
static void about_activated(GSimpleAction *action, GVariant *parameter,
gpointer app) {
//display_about_dialog(NULL, NULL) ;
return ;
}
static void preferences_activated(GSimpleAction *action, GVariant
*parameter, gpointer app) {
//configure_program_dialog(NULL, NULL) ;
return ;
}
static void quit_activated(GSimpleAction *action, GVariant *parameter,
gpointer app) {
//#ifdef DEBUG
DEBUG_FUNC_MARK
//#endif
destroy(NULL, NULL) ;
return ;
}
static void shutdown_app(GApplication *application, gpointer user_data) {
//#ifdef DEBUG
DEBUG_FUNC_MARK
//#endif
fprintf(stdout,"application shutdown\n") ;
destroy(NULL, NULL) ;
return ;
}
void destroy(GtkWidget *widget, gpointer pointer) {
//#ifdef DEBUG
DEBUG_FUNC_MARK
//#endif
exit(EXIT_SUCCESS) ;
}
static gboolean delete_event(GtkWidget *widget,GdkEvent *event,gpointer
pointer) {
#ifdef DEBUG
DEBUG_FUNC_MARK
#endif
if (event->type == GDK_DELETE) {
#ifdef DEBUG
fprintf(stdout,"%s delete_event catch\n", __func__) ;
#endif
return FALSE ;
}
else {
#ifdef DEBUG
fprintf(stdout,"%s delete_event not catch\n", __func__) ;
#endif
return FALSE ;
}
}
```
I work on a Ubuntu-Gnome system 16.10.
I don't understand why my application doesn't send any notification.
Is it a DBus problem or some other kind of underlying problem.
Thanks for your answers,
best regards,
mrcyberfighter.
--
3D imaging web-site: www.3dreaming-imaging.net
<http://www.3dreaming-imaging.net/>
International web-site: www.open-source-projects.net
<http://www.open-source-projects.net/>
--
3D imaging web-site: www.3dreaming-imaging.net
<http://www.3dreaming-imaging.net/>
International web-site: www.open-source-projects.net
<http://www.open-source-projects.net/>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]