Skip to content

Commit

Permalink
Add control panel configuration
Browse files Browse the repository at this point in the history
Based on the one from mafw-lastfm.

Signed-off-by: Felipe Contreras <[email protected]>
  • Loading branch information
felipec committed May 30, 2010
1 parent 4e4433a commit 5ba6cd5
Show file tree
Hide file tree
Showing 4 changed files with 202 additions and 3 deletions.
25 changes: 22 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ GTHREAD_LIBS := $(shell pkg-config --libs gthread-2.0)
MAFW_CFLAGS := $(shell pkg-config --cflags mafw-shared mafw)
MAFW_LIBS := $(shell pkg-config --libs mafw-shared mafw)

HILDON_CFLAGS := $(shell pkg-config --cflags hildon-1 hildon-control-panel)
HILDON_LIBS := $(shell pkg-config --libs hildon-1 hildon-control-panel)

OSSO_CFLAGS := $(shell pkg-config --cflags libosso)
OSSO_LIBS := $(shell pkg-config --libs libosso)

SCROBBLE_LIBS := $(SOUP_LIBS)

all:
Expand All @@ -30,7 +36,12 @@ mafw-scrobbler: override CFLAGS += $(GLIB_CFLAGS) $(GTHREAD_CFLAGS) $(MAFW_CFLAG
mafw-scrobbler: override LIBS += $(GLIB_LIBS) $(GTHREAD_LIBS) $(MAFW_LIBS) $(SCROBBLE_LIBS)
bins += mafw-scrobbler

all: libscrobble.a $(bins)
libcp-scrobbler.so: control_panel.o
libcp-scrobbler.so: override CFLAGS += $(HILDON_CFLAGS) $(OSSO_CFLAGS)
libcp-scrobbler.so: override LIBS += $(HILDON_LIBS) $(OSSO_LIBS)
libs += libcp-scrobbler.so

all: libscrobble.a $(bins) $(libs)

D = $(DESTDIR)

Expand All @@ -41,19 +52,27 @@ QUIET_LINK = @echo ' LINK '$@;
QUIET_CLEAN = @echo ' CLEAN '$@;
endif

install: $(bins)
install: $(bins) $(libs)
install -m 755 mafw-scrobbler -D $(D)/usr/bin/mafw-scrobbler
install -m 644 libcp-scrobbler.so -D \
$(D)/usr/lib/hildon-control-panel/libcp-scrobbler.so
install -m 644 mafw-scrobbler.desktop -D \
$(D)/usr/share/applications/hildon-control-panel/mafw-scrobbler.desktop
install -m 644 fm.png -D $(D)/usr/share/icons/hicolor/48x48/apps/fm.png

%.a::
$(QUIET_LINK)$(AR) rcs $@ $^

%.so::
$(QUIET_LINK)$(CC) $(LDFLAGS) -shared -o $@ $^ $(LIBS)

$(bins):
$(QUIET_LINK)$(CC) $(LDFLAGS) $(LIBS) -o $@ $^

%.o:: %.c
$(QUIET_CC)$(CC) $(CFLAGS) -MMD -o $@ -c $<

clean:
$(QUIET_CLEAN)$(RM) *.o *.d *.a $(bins)
$(QUIET_CLEAN)$(RM) *.o *.d *.a $(bins) $(libs)

-include *.d
171 changes: 171 additions & 0 deletions control_panel.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
/**
* Copyright (C) 2009-2010 Claudio Saavedra
* Copyright (C) 2010 Felipe Contreras
*
* This code is licenced under the GPLv2.
*/

#include <hildon-cp-plugin/hildon-cp-plugin-interface.h>
#include <hildon/hildon.h>
#include <gtk/gtk.h>
#include <libintl.h>

static gchar *file;
static GKeyFile *keyfile;

struct service {
const char *id;
GtkEntry *username;
GtkEntry *password;
};

static struct service services[] = {
{ .id = "lastfm" },
{ .id = "librefm" },
};

static void
save_credentials(void)
{

unsigned i;
for (i = 0; i < G_N_ELEMENTS(services); i++) {
struct service *s = &services[i];
g_key_file_set_string(keyfile, s->id, "username", gtk_entry_get_text(s->username));
g_key_file_set_string(keyfile, s->id, "password", gtk_entry_get_text(s->password));
}

g_file_set_contents(file,
g_key_file_to_data(keyfile, NULL, NULL),
-1, NULL);
}

static void
on_dialog_response(GtkDialog *dialog,
gint id,
gpointer user_data)
{
if (id == GTK_RESPONSE_OK)
save_credentials();

gtk_widget_hide(GTK_WIDGET(dialog));
gtk_widget_destroy(GTK_WIDGET(dialog));

g_key_file_free(keyfile);
g_free(file);
}

static void
load_credentials(void)
{
gboolean ok;

file = g_build_filename(g_get_home_dir(), ".osso", "scrobbler", NULL);

keyfile = g_key_file_new();
ok = g_key_file_load_from_file(keyfile, file, G_KEY_FILE_NONE, NULL);
if (!ok)
return;

unsigned i;
for (i = 0; i < G_N_ELEMENTS(services); i++) {
struct service *s = &services[i];
gchar *v_username, *v_password;

v_username = g_key_file_get_string(keyfile, s->id, "username", NULL);
v_password = g_key_file_get_string(keyfile, s->id, "password", NULL);
gtk_entry_set_text(s->username, v_username);
gtk_entry_set_text(s->password, v_password);
gtk_editable_select_region(GTK_EDITABLE(s->username), 0, -1);
g_free(v_username);
g_free(v_password);
}
}

static GtkWidget *
build_service(struct service *service)
{
GtkWidget *hbox;
GtkWidget *frame;
GtkWidget *fvbox;

frame = gtk_frame_new(service->id);
fvbox = gtk_vbox_new(TRUE, 0);

{
GtkWidget *label_username, *entry_username;

hbox = gtk_hbox_new(FALSE, 0);

label_username = gtk_label_new("Username:");
gtk_misc_set_alignment(GTK_MISC(label_username), 0.0, 0.5);
entry_username = hildon_entry_new(HILDON_SIZE_AUTO | HILDON_SIZE_FINGER_HEIGHT);

gtk_box_pack_start(GTK_BOX(hbox), label_username, TRUE, TRUE, 20);
gtk_box_pack_start(GTK_BOX(hbox), entry_username, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(fvbox), hbox, FALSE, FALSE, 0);

service->username = GTK_ENTRY(entry_username);
}

{
GtkWidget *label_password, *entry_password;

hbox = gtk_hbox_new(FALSE, 0);

label_password = gtk_label_new("Password:");
gtk_misc_set_alignment(GTK_MISC(label_password), 0.0, 0.5);
entry_password = hildon_entry_new(HILDON_SIZE_AUTO | HILDON_SIZE_FINGER_HEIGHT);
hildon_gtk_entry_set_input_mode(GTK_ENTRY(entry_password),
HILDON_GTK_INPUT_MODE_FULL |
HILDON_GTK_INPUT_MODE_INVISIBLE);

gtk_box_pack_start(GTK_BOX(hbox), label_password, TRUE, TRUE, 20);
gtk_box_pack_start(GTK_BOX(hbox), entry_password, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(fvbox), hbox, FALSE, FALSE, 0);

service->password = GTK_ENTRY(entry_password);
}

gtk_container_add(GTK_CONTAINER(frame), fvbox);
return frame;
}

osso_return_t
execute(osso_context_t *osso, gpointer data, gboolean user_activated)
{
GtkWidget *dialog;
GtkWidget *vbox;

dialog = gtk_dialog_new_with_buttons("Scrobbler settings",
GTK_WINDOW(data),
GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR,
dgettext("hildon-libs", "wdgt_bd_done"),
GTK_RESPONSE_OK,
NULL);
vbox = gtk_vbox_new(TRUE, 0);

unsigned i;
for (i = 0; i < G_N_ELEMENTS(services); i++) {
GtkWidget *frame;
frame = build_service(&services[i]);
gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 0);
}

load_credentials();

gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(dialog))),
vbox);

g_signal_connect(dialog, "response", G_CALLBACK(on_dialog_response), NULL);

gtk_widget_show_all(dialog);

return OSSO_OK;
}

osso_return_t
save_state(osso_context_t *osso, gpointer data)
{
return OSSO_OK;
}
Binary file added fm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions mafw-scrobbler.desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[Desktop Entry]
Encoding=UTF-8
Version=1.0
Name=Scrobbler settings
Comment=Configure your scrobbling accounts
Type=HildonControlPanelPlugin
Icon=fm
X-control-panel-plugin=libcp-scrobbler.so
Categories=extras

0 comments on commit 5ba6cd5

Please sign in to comment.