示例#1
0
void 
cid_write_keys_to_file (GKeyFile *pKeyFile, const gchar *cConfFilePath) 
{
    cid_debug ("%s (%s)", __func__, cConfFilePath);
    GError *erreur = NULL;

    gchar *cDirectory = g_path_get_dirname (cConfFilePath);
    if (! g_file_test (cDirectory, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_EXECUTABLE)) 
    {
        g_mkdir_with_parents (cDirectory, 7*8*8+7*8+5);
    }
    g_free (cDirectory);


    gsize length;
    gchar *cNewConfFilePath = g_key_file_to_data (pKeyFile, &length, &erreur);
    if (erreur != NULL) 
    {
        cid_warning ("Error while fetching data : %s", erreur->message);
        g_error_free (erreur);
        return ;
    }

    g_file_set_contents (cConfFilePath, cNewConfFilePath, length, &erreur);
    if (erreur != NULL) 
    {
        cid_warning ("Error while writing data : %s", erreur->message);
        g_error_free (erreur);
        return ;
    }
}
示例#2
0
gchar *
cid_get_string_value_full (GKeyFile *pKeyFile, gchar *cGroup, gchar *cKey, gboolean bDefault, gchar *cDefault, gboolean bFile, gboolean bDir) 
{
    GError *error = NULL;
    gchar *cGet = g_key_file_get_string (pKeyFile, cGroup, cKey, &error);
    if (error != NULL && bDefault) 
    {
        bUnvalidKey = TRUE;
        cid_warning("key '%s' in group '%s'\n=> %s",cKey,cGroup,error->message);
        g_error_free(error);
        error = NULL;
        g_free (cGet);
        cGet = g_strdup(cDefault);
    }
    if ((bFile || bDir) && cDefault != NULL && !g_file_test (cGet, bDir ? G_FILE_TEST_IS_DIR : G_FILE_TEST_EXISTS)) 
    {
        g_free (cGet);
        if (g_file_test (cDefault, bDir ? G_FILE_TEST_IS_DIR : G_FILE_TEST_EXISTS))
        {
            cid_debug ("%s:%s=%s",cGroup,cKey,cDefault);
            return cDefault;
        }
        else 
        {
            cid_debug ("%s:%s=(NULL)",cGroup,cKey);
            return NULL;
        }
    }
    cid_debug ("%s:%s=%s",cGroup,cKey,cGet);
    return cGet;
}
示例#3
0
gboolean 
cid_check_conf_file_version (CidMainContainer **pCid, const gchar *f) 
{
    gchar *cCommand=NULL;
    gchar line_f1[80], line_f2[80];
    FILE *f1, *f2;
    gchar *cOrigFile = g_strdup_printf("%s/%s",CID_DATA_DIR, CID_CONFIG_FILE);
    f1 = fopen ((const char *)cOrigFile,"r");
    f2 = fopen ((const char *)f,"r");
    g_free (cOrigFile);
    
    if (!fgets(line_f1,80,f1) || !fgets(line_f2,80,f2))
        cid_exit (3,"couldn't read conf file, try to delete it");
    
    fclose (f1);
    fclose (f2);
    
    cid_info ("line_f1 %s\nline_f2 %s",line_f1,line_f2);
        
    if (strcmp(line_f1,line_f2)!=0 || bUnvalidKey) 
    {
        cid_warning ("bad file version, building a new one\n");
        cid_remove_file (f);
        gchar *cTmpPath = g_strdup_printf("%s/%s",CID_DATA_DIR,CID_CONFIG_FILE);
        cid_copy_file(cTmpPath,f);
        g_free (cTmpPath);
        
        cid_save_data (pCid);
        cid_read_key_file (pCid, f);
        return FALSE;
    }
    return TRUE;
}
示例#4
0
gboolean 
cid_free_and_debug_error (GError **error) 
{
    if (*error != NULL) 
    {
        bUnvalidKey = TRUE;
        cid_warning("\n=> %s",(*error)->message);
        g_error_free(*error);
        *error = NULL;
        return TRUE;
    }
    return FALSE;
}
示例#5
0
gboolean 
cid_get_boolean_value_full (GKeyFile *pKeyFile, gchar *cGroup, gchar *cKey, gboolean bDefault) 
{
    GError *error = NULL;
    gboolean bGet = g_key_file_get_boolean (pKeyFile, cGroup, cKey, &error);
    if (error != NULL) 
    {
        bUnvalidKey = TRUE;
        cid_warning("key '%s' in group '%s'\n=> %s",cKey,cGroup,error->message);
        g_error_free(error);
        error = NULL;
        bGet = bDefault;
    }
    cid_debug ("%s:%s=%s",cGroup,cKey,bGet?"TRUE":"FALSE");
    return bGet;
}
示例#6
0
gint 
cid_get_int_value_full (GKeyFile *pKeyFile, gchar *cGroup, gchar *cKey, gboolean bDefault, gint iDefault, gboolean bMax, gint iMax) 
{
    GError *error = NULL;
    gint iGet = g_key_file_get_integer (pKeyFile, cGroup, cKey, &error);
    if (error != NULL && bDefault) 
    {
        bUnvalidKey = TRUE;
        cid_warning("key '%s' in group '%s'\n=> %s",cKey,cGroup,error->message);
        g_error_free(error);
        error = NULL;
        iGet = iDefault;
    }
    cid_debug ("%s:%s=%d",cGroup,cKey,(bMax && iGet > iMax)?iMax:iGet);
    if (bMax && iGet > iMax)
        return iMax;
    return iGet;
}
示例#7
0
gboolean 
cid_load_key_file(const gchar *cFile) 
{
    GKeyFileFlags flags;
    GError *error = NULL;

    /* Create a new GKeyFile object and a bitwise list of flags. */
    cid->pKeyFile = g_key_file_new ();
    flags = G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS;

    /* Load the GKeyFile or return. */
    if (!g_key_file_load_from_file (cid->pKeyFile, cFile, flags, &error)) 
    {
        cid_warning (error->message);
        g_error_free (error);
        return FALSE;
    }
    return TRUE;
}
void 
getSongInfos(void) 
{   
    GHashTable *data_list = NULL;
    GValue *value;
    const gchar *data;
    
    if(dbus_g_proxy_call (dbus_proxy_shell, "getSongProperties", NULL,
                            G_TYPE_STRING, musicData.playing_uri,
                            G_TYPE_INVALID,
                            dbus_g_type_get_map("GHashTable",G_TYPE_STRING, G_TYPE_VALUE),
                            &data_list,
                            G_TYPE_INVALID)) {
        g_free (musicData.playing_artist);
        value = (GValue *) g_hash_table_lookup(data_list, "artist");
        if (value != NULL && G_VALUE_HOLDS_STRING(value)) 
            musicData.playing_artist = g_strdup (g_value_get_string(value));
        else 
            musicData.playing_artist = NULL;
        cid_message ("  playing_artist <- %s\n", musicData.playing_artist);
        
        g_free (musicData.playing_album);
        value = (GValue *) g_hash_table_lookup(data_list, "album");
        if (value != NULL && G_VALUE_HOLDS_STRING(value)) 
            musicData.playing_album = g_strdup (g_value_get_string(value));
        else 
            musicData.playing_album = NULL;
        cid_message ("  playing_album <- %s\n", musicData.playing_album);
        
        g_free (musicData.playing_title);
        value = (GValue *) g_hash_table_lookup(data_list, "title");
        if (value != NULL && G_VALUE_HOLDS_STRING(value)) 
            musicData.playing_title = g_strdup (g_value_get_string(value));
        else 
            musicData.playing_title = NULL;
        cid_message ("  playing_title <- %s\n", musicData.playing_title);
        
        value = (GValue *) g_hash_table_lookup(data_list, "track-number");
        if (value != NULL && G_VALUE_HOLDS_UINT(value)) 
            musicData.playing_track = g_value_get_uint(value);
        else 
            musicData.playing_track = 0;
        cid_message ("  playing_track <- %d\n", musicData.playing_track);
        
        value = (GValue *) g_hash_table_lookup(data_list, "duration");
        if (value != NULL && G_VALUE_HOLDS_UINT(value)) 
            musicData.playing_duration = g_value_get_uint(value);
        else 
            musicData.playing_duration = 0;
        cid_message ("  playing_duration <- %ds\n", musicData.playing_duration);
        
        value = (GValue *) g_hash_table_lookup(data_list, "rb:coverArt-uri");
        g_free (musicData.playing_cover);
        if (value != NULL && G_VALUE_HOLDS_STRING(value)) 
        {
            GError *erreur = NULL;
            const gchar *cString = g_value_get_string(value);
            if (cString != NULL && strncmp (cString, "file://", 7) == 0) 
            {
                musicData.playing_cover = g_filename_from_uri (cString, NULL, &erreur);
                if (erreur != NULL) 
                {
                    cid_warning ("Attention : %s\n", erreur->message);
                    g_error_free (erreur);
                }
            } 
            else 
            {
                musicData.playing_cover = g_strdup (cString);
            }
        } 
        else 
        {
            CidDataTable *p_tabFiles = cid_create_datatable(G_TYPE_STRING,"cover","album","albumart",
                                                            ".folder",".cover","folder","Cover","Folder",
                                                            G_TYPE_INVALID);
            gchar *cSongPath = g_filename_from_uri (musicData.playing_uri, NULL, NULL);  // on teste d'abord dans le repertoire de la chanson.
            if (cSongPath != NULL)
            {
                gchar *cSongDir = g_path_get_dirname (cSongPath);
                g_free (cSongPath);
                musicData.playing_cover = g_strdup_printf ("%s/%s - %s.jpg", cSongDir, musicData.playing_artist, musicData.playing_album);
                cid_debug ("   test de %s\n", musicData.playing_cover);
                BEGIN_FOREACH_DT(p_tabFiles)
                    if (g_file_test (musicData.playing_cover, G_FILE_TEST_EXISTS))
                        break;
                    g_free (musicData.playing_cover);
                    musicData.playing_cover = g_strdup_printf ("%s/%s.jpg", cSongDir, p_temp->content->string);
                    cid_debug ("   test de %s\n", musicData.playing_cover);
                END_FOREACH_DT
                if (! g_file_test (musicData.playing_cover, G_FILE_TEST_EXISTS))
                {
                    cid_debug ("   test de %s (.gnome2)\n", musicData.playing_cover);
                    g_free (musicData.playing_cover);
                    musicData.playing_cover = g_strdup_printf("%s/.gnome2/rhythmbox/covers/%s - %s.jpg", g_getenv("HOME"),musicData.playing_artist, musicData.playing_album);
                }
                if (! g_file_test (musicData.playing_cover, G_FILE_TEST_EXISTS))
                {
                    cid_debug ("    test de %s (.cache)\n", musicData.playing_cover);
                    g_free (musicData.playing_cover);
                    musicData.playing_cover = g_strdup_printf("%s/.cache/rhythmbox/covers/%s - %s.jpg", g_getenv("HOME"),musicData.playing_artist, musicData.playing_album);
                }
                g_free (cSongDir);
                if (! g_file_test (musicData.playing_cover, G_FILE_TEST_EXISTS))
                {
                    cid->runtime->iCheckIter = 0;
                    if (musicData.iSidCheckCover == 0 && cid->config->iPlayer != PLAYER_NONE) 
                    {
                        cid_debug ("l'image n'existe pas encore => on boucle.\n");
                        musicData.iSidCheckCover = g_timeout_add (1 SECONDES, (GSourceFunc) _check_cover_is_present, (gpointer) NULL);
                    }
                }
            }
        }