Exemplo n.º 1
0
Arquivo: mpd.c Projeto: DeforaOS/Panel
static MPD * _mpd_init(PanelAppletHelper * helper, GtkWidget ** widget)
{
	MPD * mpd;
	GtkOrientation orientation;
	GtkIconSize iconsize;

	if((mpd = object_new(sizeof(*mpd))) == NULL)
		return NULL;
	mpd->helper = helper;
	orientation = panel_window_get_orientation(helper->window);
#if GTK_CHECK_VERSION(3, 0, 0)
	mpd->widget = gtk_box_new(orientation, 0);
#else
	mpd->widget = (orientation == GTK_ORIENTATION_HORIZONTAL)
		? gtk_hbox_new(FALSE, 0) : gtk_vbox_new(FALSE, 0);
#endif
	iconsize = panel_window_get_icon_size(helper->window);
	_init_add(mpd, GTK_STOCK_MEDIA_PREVIOUS, iconsize, _("Previous"),
			G_CALLBACK(_mpd_on_previous));
	_init_add(mpd, GTK_STOCK_MEDIA_REWIND, iconsize, _("Rewind"),
			G_CALLBACK(_mpd_on_rewind));
	_init_add(mpd, GTK_STOCK_MEDIA_PLAY, iconsize, _("Play"),
			G_CALLBACK(_mpd_on_play));
	_init_add(mpd, GTK_STOCK_MEDIA_PAUSE, iconsize, _("Pause"),
			G_CALLBACK(_mpd_on_pause));
	_init_add(mpd, GTK_STOCK_MEDIA_STOP, iconsize, _("Stop"),
			G_CALLBACK(_mpd_on_stop));
	_init_add(mpd, GTK_STOCK_MEDIA_FORWARD, iconsize, _("Forward"),
			G_CALLBACK(_mpd_on_forward));
	_init_add(mpd, GTK_STOCK_MEDIA_NEXT, iconsize, _("Next"),
			G_CALLBACK(_mpd_on_next));
	gtk_widget_show_all(mpd->widget);
	*widget = mpd->widget;
	return mpd;
}
Exemplo n.º 2
0
static void _set_image(Battery * battery, BatteryLevel level, gboolean charging)
{
	char const * icons[BATTERY_LEVEL_COUNT][2] =
	{
		{ "stock_dialog-question", "stock_dialog-question"	},
		{ "battery-missing", "battery-missing"			},
		{ "battery-empty", "battery-caution-charging"		},
		{ "battery-caution", "battery-caution-charging"		},
		{ "battery-low", "battery-low-charging"			},
		{ "battery-good", "battery-good-charging"		},
		{ "battery-full", "battery-full-charging"		}
	};

	if(battery->level == level && battery->charging == charging)
		return;
	battery->level = level;
	battery->charging = charging;
	gtk_image_set_from_icon_name(GTK_IMAGE(battery->image),
			icons[level][charging ? 1 : 0],
			panel_window_get_icon_size(battery->helper->window));
}
Exemplo n.º 3
0
/* clock_init */
static Clock * _clock_init(PanelAppletHelper * helper, GtkWidget ** widget)
{
	const int timeout = 1000;
	Clock * clock;
#ifdef EMBEDDED
	PangoFontDescription * desc;
#endif

	if((clock = object_new(sizeof(*clock))) == NULL)
		return NULL;
	clock->iconsize = panel_window_get_icon_size(helper->window);
	clock->helper = helper;
	clock->label = gtk_label_new(" \n ");
	if((clock->format = helper->config_get(helper->panel, "clock",
					"format")) == NULL)
#ifdef EMBEDDED
		clock->format = _("%H:%M");
	clock->widget = clock->label;
	desc = pango_font_description_new();
	pango_font_description_set_weight(desc, PANGO_WEIGHT_BOLD);
	gtk_widget_modify_font(clock->label, desc);
	pango_font_description_free(desc);
#else
	{
		if(clock->iconsize == GTK_ICON_SIZE_LARGE_TOOLBAR)
			clock->format = _("%H:%M:%S\n%d/%m/%Y");
		else
			clock->format = _("%H:%M");
	}
	clock->widget = gtk_frame_new(NULL);
	gtk_frame_set_shadow_type(GTK_FRAME(clock->widget), GTK_SHADOW_IN);
	gtk_container_add(GTK_CONTAINER(clock->widget), clock->label);
#endif
	gtk_label_set_justify(GTK_LABEL(clock->label), GTK_JUSTIFY_CENTER);
	clock->timeout = g_timeout_add(timeout, _clock_on_timeout, clock);
	_clock_on_timeout(clock);
	gtk_widget_show_all(clock->widget);
	*widget = clock->widget;
	return clock;
}
Exemplo n.º 4
0
/* cpufreq_init */
static Cpufreq * _cpufreq_init(PanelAppletHelper * helper, GtkWidget ** widget)
{
	const int timeout = 1000;
#if defined(__FreeBSD__) || defined(__NetBSD__)
	Cpufreq * cpufreq;
	PangoFontDescription * desc;
	GtkWidget * image;
	GtkWidget * label;
	char freq[256];
	size_t freqsize = sizeof(freq);
	char const * p;

	/* detect the correct sysctl */
	if(sysctlbyname("hw.clockrate", &freq, &freqsize, NULL, 0) == 0)
		p = "hw.clockrate";
	else if(sysctlbyname("machdep.est.frequency.available", &freq,
				&freqsize, NULL, 0) == 0)
		p = "machdep.est.frequency.current";
	else if(sysctlbyname("machdep.powernow.frequency.available", &freq,
				&freqsize, NULL, 0) == 0)
		p = "machdep.powernow.frequency.current";
	else if(sysctlbyname("machdep.frequency.available", &freq, &freqsize,
				NULL, 0) == 0)
		p = "machdep.frequency.current";
	else
	{
		error_set("%s: %s", applet.name, _("No support detected"));
		return NULL;
	}
	if((cpufreq = malloc(sizeof(*cpufreq))) == NULL)
	{
		error_set("%s: %s", applet.name, strerror(errno));
		return NULL;
	}
	cpufreq->helper = helper;
	desc = pango_font_description_new();
	pango_font_description_set_family(desc, "Monospace");
	pango_font_description_set_weight(desc, PANGO_WEIGHT_BOLD);
#if GTK_CHECK_VERSION(3, 0, 0)
	cpufreq->hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 4);
#else
	cpufreq->hbox = gtk_hbox_new(FALSE, 4);
#endif
	image = gtk_image_new_from_icon_name("gnome-monitor",
			panel_window_get_icon_size(helper->window));
	gtk_box_pack_start(GTK_BOX(cpufreq->hbox), image, FALSE, TRUE, 0);
	cpufreq->min = 0;
	cpufreq->max = 0;
	cpufreq->step = 1;
	cpufreq->name = p;
	cpufreq->max = atoi(freq);
	cpufreq->min = (p = strrchr(freq, ' ')) != NULL ? atoi(p)
		: cpufreq->max;
	cpufreq->label = gtk_label_new(" ");
#if GTK_CHECK_VERSION(3, 0, 0)
	gtk_widget_override_font(cpufreq->label, desc);
#else
	gtk_widget_modify_font(cpufreq->label, desc);
#endif
	gtk_box_pack_start(GTK_BOX(cpufreq->hbox), cpufreq->label, FALSE, TRUE,
			0);
	label = gtk_label_new(_("MHz"));
	gtk_box_pack_start(GTK_BOX(cpufreq->hbox), label, FALSE, TRUE, 0);
	if(_cpufreq_on_timeout(cpufreq) == TRUE)
		cpufreq->timeout = g_timeout_add(timeout, _cpufreq_on_timeout,
				cpufreq);
	pango_font_description_free(desc);
	gtk_widget_show_all(cpufreq->hbox);
	*widget = cpufreq->hbox;
	return cpufreq;
#else
	error_set("%s: %s", applet.name, _("Unsupported platform"));
	return NULL;
#endif
}
Exemplo n.º 5
0
/* battery_init */
static Battery * _battery_init(PanelAppletHelper * helper, GtkWidget ** widget)
{
	const int timeout = 5000;
	Battery * battery;
	GtkIconSize iconsize;
	GtkWidget * vbox;
	GtkWidget * hbox;
	PangoFontDescription * bold;

	if((battery = object_new(sizeof(*battery))) == NULL)
		return NULL;
	battery->helper = helper;
	battery->level = -1;
	battery->charging = -1;
	battery->timeout = 0;
#if defined(__NetBSD__) || defined(__linux__)
	battery->fd = -1;
#endif
	iconsize = panel_window_get_icon_size(helper->window);
#if GTK_CHECK_VERSION(3, 0, 0)
	hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 4);
#else
	hbox = gtk_hbox_new(FALSE, 4);
#endif
	battery->box = hbox;
	battery->image = gtk_image_new_from_icon_name("battery", iconsize);
	gtk_box_pack_start(GTK_BOX(hbox), battery->image, TRUE, TRUE, 0);
	battery->label = NULL;
	battery->progress = NULL;
	battery->pr_level = NULL;
	if(panel_window_get_type(helper->window)
			== PANEL_WINDOW_TYPE_NOTIFICATION)
	{
		bold = pango_font_description_new();
		pango_font_description_set_weight(bold, PANGO_WEIGHT_BOLD);
#if GTK_CHECK_VERSION(3, 0, 0)
		vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 4);
#else
		vbox = gtk_vbox_new(FALSE, 4);
#endif
		gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0);
		gtk_widget_show(hbox);
		battery->progress = gtk_progress_bar_new();
		gtk_box_pack_start(GTK_BOX(vbox), battery->progress, TRUE, TRUE,
				0);
		battery->box = vbox;
		pango_font_description_free(bold);
	}
	else
	{
#ifndef EMBEDDED
		battery->label = gtk_label_new(" ");
		gtk_box_pack_start(GTK_BOX(hbox), battery->label, FALSE, TRUE,
				0);
		gtk_widget_show(battery->label);
#endif
		battery->box = hbox;
	}
	battery->timeout = g_timeout_add(timeout, _battery_on_timeout, battery);
	_battery_on_timeout(battery);
	gtk_widget_show(battery->image);
	*widget = battery->box;
	return battery;
}