~timo-jyrinki/unity/ubuntu5180

« back to all changes in this revision

Viewing changes to src/FavoriteStoreGSettings.cpp

  • Committer: Neil Jagdish Patel
  • Date: 2010-11-03 11:44:21 UTC
  • mto: (55.350.1 unity-3.0.panel)
  • mto: This revision was merged to the branch mainline in revision 271.
  • Revision ID: neil.patel@canonical.com-20101103114421-uvvrsb782fds5pbi
Import the work done so far with Compiz

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
* Copyright (C) 2010 Canonical Ltd
 
3
*
 
4
* This program is free software: you can redistribute it and/or modify
 
5
* it under the terms of the GNU General Public License version 3 as
 
6
* published by the Free Software Foundation.
 
7
*
 
8
* This program is distributed in the hope that it will be useful,
 
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
* GNU General Public License for more details.
 
12
*
 
13
* You should have received a copy of the GNU General Public License
 
14
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
*
 
16
* Authored by: Neil Jagdish Patel <neil.patel@canonical.com>
 
17
*/
 
18
 
 
19
#include <gio/gdesktopappinfo.h>
 
20
 
 
21
#include "FavoriteStoreGSettings.h"
 
22
 
 
23
FavoriteStoreGSettings::FavoriteStoreGSettings ()
 
24
{
 
25
  m_settings = g_settings_new ("com.canonical.Unity.Launcher");
 
26
  m_favorites = NULL;
 
27
 
 
28
  Refresh ();
 
29
}
 
30
 
 
31
 
 
32
FavoriteStoreGSettings::~FavoriteStoreGSettings ()
 
33
{
 
34
  g_slist_foreach (m_favorites, (GFunc)g_free, NULL);
 
35
  g_slist_free (m_favorites);
 
36
  g_object_unref (m_settings);
 
37
}
 
38
 
 
39
void
 
40
FavoriteStoreGSettings::Refresh ()
 
41
{
 
42
  int     i = 0;
 
43
  gchar **favs;
 
44
 
 
45
  g_slist_foreach (m_favorites, (GFunc)g_free, NULL);
 
46
  g_slist_free (m_favorites);
 
47
 
 
48
  favs = g_settings_get_strv (m_settings, "favorites");
 
49
 
 
50
  while (favs[i] != NULL)
 
51
    {
 
52
      GDesktopAppInfo *info;
 
53
 
 
54
      info = g_desktop_app_info_new (favs[i]);
 
55
      
 
56
      if (info == NULL || g_desktop_app_info_get_filename (info) == NULL)
 
57
        {
 
58
          g_warning ("Unable to load GDesktopAppInfo for '%s'", favs[i]);
 
59
 
 
60
          i++;
 
61
          continue;
 
62
        }
 
63
 
 
64
      m_favorites = g_slist_append (m_favorites, g_strdup (g_desktop_app_info_get_filename (info)));
 
65
      i++;
 
66
 
 
67
      g_object_unref (info);
 
68
    }
 
69
 
 
70
  g_strfreev (favs);
 
71
}
 
72
 
 
73
GSList *
 
74
FavoriteStoreGSettings::GetFavorites ()
 
75
{
 
76
  return m_favorites;
 
77
}
 
78
 
 
79
void
 
80
FavoriteStoreGSettings::AddFavorite (const char *desktop_path,
 
81
                                     guint32     position)
 
82
{
 
83
  int     n_total_favs;
 
84
  GSList *f;
 
85
  guint32 i = 0;
 
86
 
 
87
  g_return_if_fail (desktop_path);
 
88
 
 
89
  n_total_favs = g_slist_length (m_favorites) + 1;
 
90
  
 
91
  char *favs[n_total_favs + 1];
 
92
  favs[n_total_favs] = NULL;
 
93
 
 
94
  for (f = m_favorites; f; f = f->next)
 
95
    {
 
96
      if (i == position)
 
97
        {
 
98
          favs[i] = g_path_get_basename (desktop_path);
 
99
          i++;
 
100
        }
 
101
      
 
102
      favs[i] = g_path_get_basename ((char *)f->data);
 
103
 
 
104
      i++;
 
105
    }
 
106
 
 
107
  if (!g_settings_set_strv (m_settings, "favorites", favs))
 
108
    g_warning ("Unable to add a new favorite");
 
109
 
 
110
  i = 0;
 
111
  while (favs[i] != NULL)
 
112
    {
 
113
      g_free (favs[i]);
 
114
      favs[i] = NULL;
 
115
      i++;
 
116
    }
 
117
}
 
118
 
 
119
void
 
120
FavoriteStoreGSettings::RemoveFavorite (const char *desktop_path)
 
121
{
 
122
  int     n_total_favs;
 
123
  GSList *f;
 
124
  int     i = 0;
 
125
 
 
126
  g_return_if_fail (desktop_path);
 
127
 
 
128
  n_total_favs = g_slist_length (m_favorites) - 1;
 
129
  
 
130
  char *favs[n_total_favs + 1];
 
131
  favs[n_total_favs] = NULL;
 
132
 
 
133
  for (f = m_favorites; f; f = f->next)
 
134
    {
 
135
      if (g_strcmp0 ((char *)f->data, desktop_path))
 
136
        {
 
137
          favs[i] = g_path_get_basename ((char *)f->data);
 
138
          i++;
 
139
        }
 
140
    }
 
141
 
 
142
  if (!g_settings_set_strv (m_settings, "favorites", favs))
 
143
    g_warning ("Unable to add a new favorite");
 
144
 
 
145
  i = 0;
 
146
  while (favs[i] != NULL)
 
147
    {
 
148
      g_free (favs[i]);
 
149
      favs[i] = NULL;
 
150
      i++;
 
151
    }
 
152
}
 
153
 
 
154
void
 
155
FavoriteStoreGSettings::MoveFavorite (const char *desktop_path,
 
156
                                      guint32     position)
 
157
{
 
158
}