Beispiel #1
0
	void DisplayBattery(int col, int row)
	{
	#ifdef VX670

		char font[256] = {0};
		char bat[2];
		bat[0] = 'a' + (char)((get_battery_charge() * 6) / 100);
		bat[1] = 0;

		int old = get_display_coordinate_mode();
		set_display_coordinate_mode(CHARACTER_MODE);
		get_font(font);
		set_font("F:BATTERY.VFT");

		write_at (bat, 1, col, row);

		set_font(font);
		set_display_coordinate_mode(old);	

	#endif
	}
Beispiel #2
0
int main(int argc, char *argv[])
{
    GtkWidget*  window;
    shareMgr_t* theShareMgr;
    int         nRet;
    gboolean    ok;

    // catch the SIGTERM signal
    struct sigaction on_term;
    memset(&on_term, 0x00, sizeof(on_term));
    on_term.sa_handler = on_sigterm;
    sigaction(SIGTERM, &on_term, NULL);

    DL_WARNPRINTF(PACKAGE_STRING);

    parse_arguments(argc, argv);

    // minimum battery charge required for background mode
    if (g_background)
    {
        if (get_battery_charge() <= BATTERY_MINCHARGE_BACKGROUND)
        {
            DL_ERRORPRINTF("Insufficient battery [%d] for background PC connect -> quit", get_battery_charge());
            return NO_ERROR;
        }
    }
    
    /* init threads */
    g_thread_init(NULL);
    gdk_threads_init();

    // open the RC file associated with this program (re-use the downloadMgr one)
    gtk_rc_parse(DATA_DIR "/downloadMgr.rc");
    DL_LOGPRINTF("rc file %s", DATA_DIR "/downloadMgr.rc");

    gtk_init(&argc, &argv);

    load_registry();
    languagesInit();
    
    // create/init the channel to communicate with the content lister
    nRet = erIpcStartClient(ER_CONTENTLISTER_CHANNEL, &contentListerChannel);
    if (nRet != 0)
    {
        DL_ERRORPRINTF("erIpcStartClient returned %d", nRet);
        contentListerChannel = NULL;
    }

    // create the main, top level, window 
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title(GTK_WINDOW(window), PACKAGE " " VERSION);
    gtk_window_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
    gtk_container_set_border_width(GTK_CONTAINER(window), 0);
    // gtk_widget_set_size_request(GTK_WIDGET(window), SCREEN_WIDTH, SCREEN_HEIGHT);
    gtk_window_set_modal(GTK_WINDOW(window), FALSE);
    gtk_window_set_resizable(GTK_WINDOW(window), FALSE);
    gtk_window_fullscreen(GTK_WINDOW(window)); // Fullscreen overlap taskbars

    theShareMgr = ctrlInit(window);

    if (theShareMgr)
    {
        // Connect the destroy event of the window with our on_destroy function
        // When the window is about to be destroyed we get a notification and
        // stop the main GTK loop
        g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(on_destroy), NULL);

        // make sure that everything, window and label, are visible 
        if ( !g_background )
        {
            gtk_widget_show(window);
        }
    }

    // Start the download thread
    ok = shareThread_start((gpointer)theShareMgr);
    if (!ok)
    {
        printf("%s %s: ", __FILE__, __FUNCTION__);
        perror("Could not create thread\n");
    }

    // run the GTK main loop
    DL_LOGPRINTF("Before gtk_main");
    gdk_threads_enter();
    gtk_main();
    gdk_threads_leave();
    nRet = theShareMgr->returnVal;
    DL_LOGPRINTF("exitValue after gtk_main [%d]", nRet);

    // GTK done, abort any copying that might be running
    shareThread_stop();
    shareThread_wait(15);

    DL_WARNPRINTF("PC Share Manager quitting with return value \"%d\"", nRet);
    ctrlDestroy(theShareMgr);

    release_registry();

    return nRet;
}
Beispiel #3
0
static void update_tray_icon_status (GtkStatusIcon *tray_icon)
{
    gboolean battery_present = FALSE;
    gboolean ac_online       = FALSE;

    gint battery_status            = -1;
    static gint old_battery_status = -1;

    static gboolean battery_low            = FALSE;
    static gboolean battery_critical       = FALSE;
    static gboolean spawn_command_critical = FALSE;

    gint percentage, time;
    gchar *battery_string, *time_string;
    GError *error = NULL;
#ifdef WITH_NOTIFY
    NotifyNotification *notification = NULL;
#endif

    g_return_if_fail (tray_icon != NULL);

    /* update tray icon for AC only */
    if (battery_path == NULL) {
        static gboolean ac_notified = FALSE;

        if (ac_notified == FALSE) {
            ac_notified = TRUE;
            NOTIFY_MESSAGE (&notification, _("AC only, no battery!"), NULL, NOTIFY_EXPIRES_NEVER, NOTIFY_URGENCY_NORMAL);
        }

        gtk_status_icon_set_tooltip_text (tray_icon, _("AC only, no battery!"));
        gtk_status_icon_set_from_icon_name (tray_icon, "ac-adapter");

        return;
    }

    /* update tray icon for battery */
    if (get_battery_present (&battery_present) == FALSE) {
        return;
    }

    if (battery_present == FALSE) {
        battery_status = MISSING;
    } else {
        if (get_battery_status (&battery_status) == FALSE) {
            return;
        }

        /* workaround for limited/bugged batteries/drivers */
        /* that unduly return unknown status               */
        if (battery_status == UNKNOWN && get_ac_online (&ac_online) == TRUE) {
            if (ac_online == TRUE) {
                battery_status = CHARGING;

                if (get_battery_charge (FALSE, &percentage, NULL) == TRUE && percentage >= 99) {
                    battery_status = CHARGED;
                }
            } else {
                battery_status = DISCHARGING;
            }
        }
    }

    #define HANDLE_BATTERY_STATUS(PCT,TIM,EXP,URG)                                                          \
                                                                                                            \
            percentage = PCT;                                                                               \
                                                                                                            \
            battery_string = get_battery_string (battery_status, percentage);                               \
            time_string    = get_time_string (TIM);                                                         \
                                                                                                            \
            if (old_battery_status != battery_status) {                                                     \
                old_battery_status  = battery_status;                                                       \
                NOTIFY_MESSAGE (&notification, battery_string, time_string, EXP, URG);                      \
            }                                                                                               \
                                                                                                            \
            gtk_status_icon_set_tooltip_text (tray_icon, get_tooltip_string (battery_string, time_string)); \
            gtk_status_icon_set_from_icon_name (tray_icon, get_icon_name (battery_status, percentage));

    switch (battery_status) {
        case MISSING:
            HANDLE_BATTERY_STATUS (0, -1, NOTIFY_EXPIRES_NEVER, NOTIFY_URGENCY_NORMAL)
            break;

        case UNKNOWN:
            HANDLE_BATTERY_STATUS (0, -1, NOTIFY_EXPIRES_DEFAULT, NOTIFY_URGENCY_NORMAL)
            break;

        case CHARGED:
            HANDLE_BATTERY_STATUS (100, -1, NOTIFY_EXPIRES_DEFAULT, NOTIFY_URGENCY_NORMAL)
            break;

        case CHARGING:
            if (old_battery_status != CHARGING && estimation_needed == TRUE) {
                reset_battery_time_estimation ();
            }

            if (get_battery_charge (FALSE, &percentage, &time) == FALSE) {
                return;
            }

            HANDLE_BATTERY_STATUS (percentage, time, NOTIFY_EXPIRES_DEFAULT, NOTIFY_URGENCY_NORMAL)
            break;

        case DISCHARGING:
        case NOT_CHARGING:
            if (old_battery_status != DISCHARGING && estimation_needed == TRUE) {
                reset_battery_time_estimation ();
            }

            if (get_battery_charge (TRUE, &percentage, &time) == FALSE) {
                return;
            }

            battery_string = get_battery_string (battery_status, percentage);
            time_string    = get_time_string (time);

            if (old_battery_status != DISCHARGING) {
                old_battery_status  = DISCHARGING;
                NOTIFY_MESSAGE (&notification, battery_string, time_string, NOTIFY_EXPIRES_DEFAULT, NOTIFY_URGENCY_NORMAL);

                battery_low            = FALSE;
                battery_critical       = FALSE;
                spawn_command_critical = FALSE;
            }

            if (battery_low == FALSE && percentage <= configuration.low_level) {
                battery_low = TRUE;

                battery_string = get_battery_string (LOW_LEVEL, percentage);
                NOTIFY_MESSAGE (&notification, battery_string, time_string, NOTIFY_EXPIRES_NEVER, NOTIFY_URGENCY_NORMAL);
            }

            if (battery_critical == FALSE && percentage <= configuration.critical_level) {
                battery_critical = TRUE;

                battery_string = get_battery_string (CRITICAL_LEVEL, percentage);
                NOTIFY_MESSAGE (&notification, battery_string, time_string, NOTIFY_EXPIRES_NEVER, NOTIFY_URGENCY_CRITICAL);

                spawn_command_critical = TRUE;
            }

            gtk_status_icon_set_tooltip_text (tray_icon, get_tooltip_string (battery_string, time_string));
            gtk_status_icon_set_from_icon_name (tray_icon, get_icon_name (battery_status, percentage));

            if (spawn_command_critical == TRUE) {
                spawn_command_critical = FALSE;

                if (configuration.command_critical_level != NULL) {
                    syslog (LOG_CRIT, _("Spawning critical battery level command in 30 seconds: %s"), configuration.command_critical_level);
                    g_usleep (G_USEC_PER_SEC * 30);

                    if (g_spawn_command_line_async (configuration.command_critical_level, &error) == FALSE) {
                        syslog (LOG_CRIT, _("Cannot spawn critical battery level command: %s"), error->message);
                        g_error_free (error); error = NULL;

                        NOTIFY_MESSAGE (&notification, _("Cannot spawn critical battery level command!"), configuration.command_critical_level, NOTIFY_EXPIRES_NEVER, NOTIFY_URGENCY_CRITICAL);
                    }
                }
            }
            break;
    }
}