~unity-2d-team/unity-2d/maverick

« back to all changes in this revision

Viewing changes to launcher/UnityApplications/webfavorite.cpp

  • Committer: Florian Boucault
  • Date: 2011-04-22 15:01:24 UTC
  • Revision ID: florian@boucault.net-20110422150124-72jeot6nh3k1bv0b
[core] Introduces GScopedPointer and GObjectScopedPointer, two smart pointers which makes it easier to deal with C structures without forgetting to release them.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
#include "webfavorite.h"
23
23
 
 
24
// libunity-2d
 
25
#include <gscopedpointer.h>
 
26
 
 
27
// Qt
24
28
#include <QDir>
25
29
#include <QtNetwork/QNetworkAccessManager>
26
30
#include <QtNetwork/QNetworkRequest>
92
96
    file.close();
93
97
}
94
98
 
 
99
typedef GScopedPointer<GKeyFile, g_key_file_free> GKeyFilePointer;
 
100
 
95
101
void
96
102
WebFavorite::modifyDesktopFile(const QString& key, const QString& value) const
97
103
{
98
 
    GKeyFile* keyFile = g_key_file_new();
99
 
    gboolean loaded = g_key_file_load_from_file(keyFile, m_desktopFile.toUtf8().constData(),
 
104
    GKeyFilePointer keyFile(g_key_file_new());
 
105
    gboolean loaded = g_key_file_load_from_file(keyFile.data(), m_desktopFile.toUtf8().constData(),
100
106
        (GKeyFileFlags) (G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS), NULL);
101
107
    if (loaded) {
102
 
        g_key_file_set_string(keyFile, "Desktop Entry", key.toUtf8().constData(), value.toUtf8().constData());
103
 
        QByteArray contents = g_key_file_to_data(keyFile, NULL, NULL);
 
108
        g_key_file_set_string(keyFile.data(), "Desktop Entry", key.toUtf8().constData(), value.toUtf8().constData());
 
109
        QByteArray contents = g_key_file_to_data(keyFile.data(), NULL, NULL);
104
110
        writeDesktopFile(contents);
105
111
    }
106
 
    g_key_file_free(keyFile);
107
112
}
108
113
 
109
114
void