Beispiel #1
0
DrWright *
drwright_new (void)
{
	DrWright *dr = g_new0 (DrWright, 1);

	if (debug) {
		setup_debug_values (dr);
	}

	if (!notify_is_initted ()) {
		notify_init (g_get_application_name ());
	}

	dr->timer = drw_timer_new ();
	dr->idle_timer = drw_timer_new ();

	dr->state = STATE_START;

	dr->monitor = drw_monitor_new ();

	g_signal_connect (dr->monitor,
			  "activity",
			  G_CALLBACK (activity_detected_cb),
			  dr);

	g_timeout_add_seconds (1,
			       (GSourceFunc) maybe_change_state,
			       dr);

        dr->settings = g_settings_new (DRW_SETTINGS_SCHEMA_ID);
        settings_change_cb (dr->settings, NULL, dr);
        g_signal_connect (dr->settings, "changed",
                          G_CALLBACK (settings_change_cb), dr);

	return dr;
}
DrWright *
drwright_new (void)
{
    DrWright  *dr;
    GtkWidget *item;
    MateConfClient *client;
    GtkActionGroup *action_group;

    static const char ui_description[] =
        "<ui>"
        "  <popup name='Pop'>"
        "    <menuitem action='Preferences'/>"
        "    <menuitem action='About'/>"
        "    <separator/>"
        "    <menuitem action='TakeABreak'/>"
        "  </popup>"
        "</ui>";

    dr = g_new0 (DrWright, 1);

    client = mateconf_client_get_default ();

    mateconf_client_add_dir (client,
                             MATECONF_PATH,
                             MATECONF_CLIENT_PRELOAD_NONE,
                             NULL);

    mateconf_client_notify_add (client, MATECONF_PATH,
                                mateconf_notify_cb,
                                dr,
                                NULL,
                                NULL);

    dr->type_time = 60 * mateconf_client_get_int (
                        client, MATECONF_PATH "/type_time", NULL);

    dr->warn_time = MIN (dr->type_time / 12, 60*3);

    dr->break_time = 60 * mateconf_client_get_int (
                         client, MATECONF_PATH "/break_time", NULL);

    dr->enabled = mateconf_client_get_bool (
                      client,
                      MATECONF_PATH "/enabled",
                      NULL);

    g_object_unref (client);

    if (debug) {
        setup_debug_values (dr);
    }

    dr->ui_manager = gtk_ui_manager_new ();

    action_group = gtk_action_group_new ("MenuActions");
    gtk_action_group_set_translation_domain (action_group, GETTEXT_PACKAGE);
    gtk_action_group_add_actions (action_group, actions, G_N_ELEMENTS (actions), dr);
    gtk_ui_manager_insert_action_group (dr->ui_manager, action_group, 0);
    gtk_ui_manager_add_ui_from_string (dr->ui_manager, ui_description, -1, NULL);

    item = gtk_ui_manager_get_widget (dr->ui_manager, "/Pop/TakeABreak");
    gtk_widget_set_sensitive (item, dr->enabled);

    dr->timer = drw_timer_new ();
    dr->idle_timer = drw_timer_new ();

    dr->state = STATE_START;

    dr->monitor = drw_monitor_new ();

    g_signal_connect (dr->monitor,
                      "activity",
                      G_CALLBACK (activity_detected_cb),
                      dr);

#ifdef HAVE_APP_INDICATOR
    init_app_indicator (dr);
#else
    dr->neutral_bar = gdk_pixbuf_new_from_file (IMAGEDIR "/bar.png", NULL);
    dr->red_bar = gdk_pixbuf_new_from_file (IMAGEDIR "/bar-red.png", NULL);
    dr->green_bar = gdk_pixbuf_new_from_file (IMAGEDIR "/bar-green.png", NULL);
    dr->disabled_bar = gdk_pixbuf_new_from_file (IMAGEDIR "/bar-disabled.png", NULL);

    init_tray_icon (dr);
#endif /* HAVE_APP_INDICATOR */

    g_timeout_add_seconds (12,
                           (GSourceFunc) update_status,
                           dr);

    g_timeout_add_seconds (1,
                           (GSourceFunc) maybe_change_state,
                           dr);

    return dr;
}
DrWright *
drwright_new (void)
{
	DrWright  *dr;
	GtkWidget *item;
	GConfClient *client;

        dr = g_new0 (DrWright, 1);

	client = gconf_client_get_default ();

	gconf_client_add_dir (client,
			      GCONF_PATH,
			      GCONF_CLIENT_PRELOAD_NONE,
			      NULL);

	gconf_client_notify_add (client, GCONF_PATH,
				 gconf_notify_cb,
				 dr,
				 NULL,
				 NULL);

	dr->type_time = 60 * gconf_client_get_int (
		client, GCONF_PATH "/type_time", NULL);

	dr->warn_time = MIN (dr->type_time / 12, 60*3);

	dr->break_time = 60 * gconf_client_get_int (
		client, GCONF_PATH "/break_time", NULL);

	dr->enabled = gconf_client_get_bool (
		client,
		GCONF_PATH "/enabled",
		NULL);

	g_object_unref (client);

	if (debug) {
		setup_debug_values (dr);
	}

	dr->popup_factory = gtk_item_factory_new (GTK_TYPE_MENU,
						      "<main>",
						      NULL);
	gtk_item_factory_set_translate_func (dr->popup_factory,
					     item_factory_trans_cb,
					     NULL,
					     NULL);

	gtk_item_factory_create_items (dr->popup_factory,
				       G_N_ELEMENTS (popup_items),
				       popup_items,
				       dr);

	/*item = gtk_item_factory_get_widget_by_action (dr->popup_factory, POPUP_ITEM_ENABLED);
	gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), dr->enabled);*/

	item = gtk_item_factory_get_widget_by_action (dr->popup_factory, POPUP_ITEM_BREAK);
	gtk_widget_set_sensitive (item, dr->enabled);

	dr->timer = g_timer_new ();
	dr->idle_timer = g_timer_new ();

	dr->state = STATE_START;

	dr->monitor = drw_monitor_new ();

	g_signal_connect (dr->monitor,
			  "activity",
			  G_CALLBACK (activity_detected_cb),
			  dr);

	dr->neutral_bar = gdk_pixbuf_new_from_file (IMAGEDIR "/bar.png", NULL);
	dr->red_bar = gdk_pixbuf_new_from_file (IMAGEDIR "/bar-red.png", NULL);
	dr->green_bar = gdk_pixbuf_new_from_file (IMAGEDIR "/bar-green.png", NULL);
	dr->disabled_bar = gdk_pixbuf_new_from_file (IMAGEDIR "/bar-disabled.png", NULL);

	init_tray_icon (dr);

	g_timeout_add_seconds (12,
		       (GSourceFunc) update_tooltip,
		       dr);
	g_timeout_add_seconds (1,
		       (GSourceFunc) maybe_change_state,
		       dr);

	return dr;
}