Skip to content

Commit

Permalink
Port lastfm_support and lastfm_user to PraghaPreferences.
Browse files Browse the repository at this point in the history
TODO:
* Port lastfm password without adding the property to PraghaPreferences.
* So, not save it in memory. Only search when necessary.
* Maybe save the hexadecimal characters to hide the password.
  • Loading branch information
matiasdelellis committed Jun 25, 2013
1 parent bccbe56 commit ac605db
Show file tree
Hide file tree
Showing 8 changed files with 176 additions and 76 deletions.
28 changes: 0 additions & 28 deletions src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,6 @@ gint init_config(struct con_win *cwin)
CDEBUG(DBG_INFO, "Initializing configuration");

start_mode_f = window_size_f = window_position_f = album_f = FALSE;
#ifdef HAVE_LIBCLASTFM
gboolean lastfm_f = FALSE;
#endif

all_f = FALSE;

Expand Down Expand Up @@ -174,27 +171,6 @@ gint init_config(struct con_win *cwin)

/* Retrieve Services Internet preferences */
#ifdef HAVE_LIBCLASTFM
cwin->cpref->lastfm_support =
g_key_file_get_boolean(cwin->cpref->configrc_keyfile,
GROUP_SERVICES,
KEY_LASTFM,
&error);
if (error) {
g_error_free(error);
error = NULL;
lastfm_f = TRUE;
}

cwin->cpref->lastfm_user =
g_key_file_get_string(cwin->cpref->configrc_keyfile,
GROUP_SERVICES,
KEY_LASTFM_USER,
&error);
if (error) {
g_error_free(error);
error = NULL;
}

cwin->cpref->lastfm_pass =
g_key_file_get_string(cwin->cpref->configrc_keyfile,
GROUP_SERVICES,
Expand Down Expand Up @@ -222,10 +198,6 @@ gint init_config(struct con_win *cwin)
}
if (all_f || start_mode_f)
cwin->cpref->start_mode = g_strdup(NORMAL_STATE);
#ifdef HAVE_LIBCLASTFM
if (all_f || lastfm_f)
cwin->cpref->lastfm_support = FALSE;
#endif

if (err)
return -1;
Expand Down
2 changes: 1 addition & 1 deletion src/pragha-glyr.c
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ update_related_handler (gpointer data)
CDEBUG(DBG_INFO, "Updating Lastm and getting the cover art depending preferences");

#ifdef HAVE_LIBCLASTFM
if (cwin->cpref->lastfm_support)
if (pragha_preferences_get_lastfm_support (cwin->preferences))
lastfm_now_playing_handler(cwin);
#endif
#ifdef HAVE_LIBGLYR
Expand Down
24 changes: 12 additions & 12 deletions src/pragha-lastfm.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ update_menubar_lastfm_state (struct con_win *cwin)
gboolean playing = pragha_backend_get_state (cwin->backend) != ST_STOPPED;
gboolean logged = cwin->clastfm->status == LASTFM_STATUS_OK;
gboolean lfm_inited = cwin->clastfm->session_id != NULL;
gboolean has_user = lfm_inited && string_is_not_empty(cwin->cpref->lastfm_user);
gboolean has_user = lfm_inited && string_is_not_empty(pragha_preferences_get_lastfm_user(cwin->preferences));

action = gtk_ui_manager_get_action(cwin->bar_context_menu, "/Menubar/ToolsMenu/Lastfm/Love track");
gtk_action_set_sensitive (GTK_ACTION (action), playing && logged);
Expand Down Expand Up @@ -587,9 +587,9 @@ do_lastfm_add_favorites_action (gpointer user_data)

do {
rpages = LASTFM_user_get_loved_tracks(cwin->clastfm->session_id,
cwin->cpref->lastfm_user,
cpage,
&results);
pragha_preferences_get_lastfm_user(cwin->preferences),
cpage,
&results);

for(li=results; li; li=li->next) {
track = li->data;
Expand All @@ -615,7 +615,7 @@ lastfm_add_favorites_action (GtkAction *action, struct con_win *cwin)
CDEBUG(DBG_LASTFM, "Add Favorites action");

if ((cwin->clastfm->session_id == NULL) ||
string_is_empty(cwin->cpref->lastfm_user)) {
string_is_empty(pragha_preferences_get_lastfm_user(cwin->preferences))) {
pragha_statusbar_set_misc_text(cwin->statusbar, _("No connection Last.fm has been established."));
return;
}
Expand Down Expand Up @@ -921,7 +921,7 @@ lastfm_now_playing_handler (struct con_win *cwin)
if(pragha_backend_get_state (cwin->backend) == ST_STOPPED)
return;

if(string_is_empty(cwin->cpref->lastfm_user) ||
if(string_is_empty(pragha_preferences_get_lastfm_user(cwin->preferences)) ||
string_is_empty(cwin->cpref->lastfm_pass))
return;

Expand Down Expand Up @@ -975,10 +975,10 @@ do_just_init_lastfm(gpointer data)
cwin->clastfm->session_id = LASTFM_init(LASTFM_API_KEY, LASTFM_SECRET);

if (cwin->clastfm->session_id != NULL) {
if(string_is_not_empty(cwin->cpref->lastfm_user) &&
if(string_is_not_empty(pragha_preferences_get_lastfm_user(cwin->preferences)) &&
string_is_not_empty(cwin->cpref->lastfm_pass)) {
cwin->clastfm->status = LASTFM_login (cwin->clastfm->session_id,
cwin->cpref->lastfm_user,
pragha_preferences_get_lastfm_user(cwin->preferences),
cwin->cpref->lastfm_pass);

if(cwin->clastfm->status != LASTFM_STATUS_OK) {
Expand All @@ -999,7 +999,7 @@ do_just_init_lastfm(gpointer data)
gint
just_init_lastfm (struct con_win *cwin)
{
if (cwin->cpref->lastfm_support) {
if (pragha_preferences_get_lastfm_support (cwin->preferences)) {
CDEBUG(DBG_INFO, "Initializing LASTFM");
g_idle_add (do_just_init_lastfm, cwin);
}
Expand All @@ -1017,10 +1017,10 @@ do_init_lastfm_idle(gpointer data)
cwin->clastfm->session_id = LASTFM_init(LASTFM_API_KEY, LASTFM_SECRET);

if (cwin->clastfm->session_id != NULL) {
if(string_is_not_empty(cwin->cpref->lastfm_user) &&
if(string_is_not_empty(pragha_preferences_get_lastfm_user(cwin->preferences)) &&
string_is_not_empty(cwin->cpref->lastfm_pass)) {
cwin->clastfm->status = LASTFM_login (cwin->clastfm->session_id,
cwin->cpref->lastfm_user,
pragha_preferences_get_lastfm_user(cwin->preferences),
cwin->cpref->lastfm_pass);

if(cwin->clastfm->status != LASTFM_STATUS_OK)
Expand Down Expand Up @@ -1049,7 +1049,7 @@ init_lastfm(struct con_win *cwin)

/* Test internet and launch threads.*/

if (cwin->cpref->lastfm_support) {
if (pragha_preferences_get_lastfm_support (cwin->preferences)) {
CDEBUG(DBG_INFO, "Initializing LASTFM");

#if GLIB_CHECK_VERSION(2,32,0)
Expand Down
43 changes: 12 additions & 31 deletions src/pragha-preferences-dialog.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,23 +332,18 @@ static void pref_dialog_cb(GtkDialog *dialog, gint response_id,

/* Services internet preferences */
#ifdef HAVE_LIBCLASTFM
cwin->cpref->lastfm_support =
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
cwin->preferences_w->lastfm_w));
pragha_preferences_set_lastfm_support (cwin->preferences,
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(cwin->preferences_w->lastfm_w)));

if (cwin->cpref->lastfm_user) {
g_free(cwin->cpref->lastfm_user);
cwin->cpref->lastfm_user = NULL;
}
if (cwin->cpref->lastfm_pass) {
g_free(cwin->cpref->lastfm_pass);
cwin->cpref->lastfm_pass = NULL;
}

if (cwin->cpref->lastfm_support) {
cwin->cpref->lastfm_user =
g_strdup(gtk_entry_get_text(GTK_ENTRY(
cwin->preferences_w->lastfm_uname_w)));
if (pragha_preferences_get_lastfm_support (cwin->preferences)) {
pragha_preferences_set_lastfm_user (cwin->preferences,
gtk_entry_get_text(GTK_ENTRY(cwin->preferences_w->lastfm_uname_w)));

cwin->cpref->lastfm_pass =
g_strdup(gtk_entry_get_text(GTK_ENTRY(
cwin->preferences_w->lastfm_pass_w)));
Expand Down Expand Up @@ -794,14 +789,13 @@ static void update_preferences(struct con_win *cwin)

/* Service Internet Option */
#ifdef HAVE_LIBCLASTFM
if (cwin->cpref->lastfm_support) {
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(
cwin->preferences_w->lastfm_w),
TRUE);
if (pragha_preferences_get_lastfm_support (cwin->preferences)) {
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cwin->preferences_w->lastfm_w), TRUE);

gtk_entry_set_text(GTK_ENTRY(cwin->preferences_w->lastfm_uname_w),
cwin->cpref->lastfm_user);
pragha_preferences_get_lastfm_user (cwin->preferences));
gtk_entry_set_text(GTK_ENTRY(cwin->preferences_w->lastfm_pass_w),
cwin->cpref->lastfm_pass);
cwin->cpref->lastfm_pass);
}
#endif
#ifdef HAVE_LIBGLYR
Expand Down Expand Up @@ -917,25 +911,12 @@ void save_preferences(struct con_win *cwin)
/* Services internet */
/* Save last.fm option */
#ifdef HAVE_LIBCLASTFM
g_key_file_set_boolean(cwin->cpref->configrc_keyfile,
GROUP_SERVICES,
KEY_LASTFM,
cwin->cpref->lastfm_support);

if (!cwin->cpref->lastfm_support) {
pragha_preferences_remove_key(cwin->preferences,
GROUP_SERVICES,
KEY_LASTFM_USER);
if (!pragha_preferences_get_lastfm_support (cwin->preferences)) {
pragha_preferences_remove_key(cwin->preferences,
GROUP_SERVICES,
KEY_LASTFM_PASS);
}
else {
if (cwin->cpref->lastfm_user)
g_key_file_set_string(cwin->cpref->configrc_keyfile,
GROUP_SERVICES,
KEY_LASTFM_USER,
cwin->cpref->lastfm_user);
if (cwin->cpref->lastfm_pass)
g_key_file_set_string(cwin->cpref->configrc_keyfile,
GROUP_SERVICES,
Expand Down
Loading

1 comment on commit ac605db

@matiasdelellis
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be interesting (much better that libgnome-keyring), but far from being a priority at this time.. 😅

Shame that depends on glib 2.32, and to continue with the plan of dependencies would have to make it optional.

Honestly, I'm tired of worrying about the dependencies!. haha.
For now, i just think about continue the cleaning of code, which luckily is well underway.. But it takes time. and now I'm busy.

Regards.

Please sign in to comment.