~azzar1/unity/fix-trash-li-blocking

« back to all changes in this revision

Viewing changes to plugins/unityshell/src/FavoriteStoreGSettings.cpp

  • Committer: Daniel van Vugt
  • Date: 2012-03-14 06:24:18 UTC
  • mfrom: (2108 unity)
  • mto: This revision was merged to the branch mainline in revision 2146.
  • Revision ID: daniel.van.vugt@canonical.com-20120314062418-nprucpbr0m7qky5e
MergedĀ latestĀ lp:unity

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
* Authored by: Neil Jagdish Patel <neil.patel@canonical.com>
18
18
*/
19
19
 
20
 
#include "FavoriteStoreGSettings.h"
21
 
 
22
20
#include <algorithm>
23
 
#include <iostream>
24
21
 
25
22
#include <gio/gdesktopappinfo.h>
26
 
 
27
23
#include <NuxCore/Logger.h>
28
24
 
 
25
#include "FavoriteStoreGSettings.h"
 
26
#include "FavoriteStorePrivate.h"
 
27
 
29
28
#include "config.h"
30
29
 
31
30
/**
103
102
 
104
103
void FavoriteStoreGSettings::Refresh()
105
104
{
106
 
  favorites_.clear();
 
105
  FillList(favorites_);
 
106
}
 
107
 
 
108
void FavoriteStoreGSettings::FillList(FavoriteList& list)
 
109
{
 
110
  list.clear();
107
111
 
108
112
  gchar** favs = g_settings_get_strv(settings_, "favorites");
109
113
 
114
118
    {
115
119
      if (g_file_test(favs[i], G_FILE_TEST_EXISTS))
116
120
      {
117
 
        favorites_.push_back(favs[i]);
 
121
        list.push_back(favs[i]);
118
122
      }
119
123
      else
120
124
      {
131
135
 
132
136
      if (filename)
133
137
      {
134
 
        favorites_.push_back(filename);
 
138
        list.push_back(filename);
135
139
      }
136
140
      else
137
141
      {
138
 
        LOG_WARNING(logger) << "Unable to load GDesktopAppInfo for '"
139
 
                         << favs[i] << "'";
 
142
        LOG_WARNING(logger) << "Unable to load GDesktopAppInfo for '" << favs[i] << "'";
140
143
      }
141
144
    }
142
145
  }
222
225
  Refresh();
223
226
}
224
227
 
225
 
void FavoriteStoreGSettings::SaveFavorites(FavoriteList const& favorites)
 
228
void FavoriteStoreGSettings::SaveFavorites(FavoriteList const& favorites, bool ignore)
226
229
{
227
230
  const int size = favorites.size();
228
231
  const char* favs[size + 1];
244
247
    favs[index] = iter->c_str();
245
248
  }
246
249
 
247
 
  ignore_signals_ = true;
 
250
  ignore_signals_ = ignore;
248
251
  if (!g_settings_set_strv(settings_, "favorites", favs))
249
252
  {
250
253
    LOG_WARNING(logger) << "Saving favorites failed.";
254
257
 
255
258
void FavoriteStoreGSettings::Changed(std::string const& key)
256
259
{
257
 
  if (ignore_signals_)
 
260
  if (ignore_signals_ or key != "favorites")
258
261
    return;
259
 
 
260
 
  LOG_DEBUG(logger) << "Changed: " << key;
 
262
    
 
263
  FavoriteList old(favorites_);
 
264
  FillList(favorites_);
 
265
 
 
266
  auto newbies = impl::GetNewbies(old, favorites_);
 
267
 
 
268
  for (auto it : favorites_)
 
269
  {
 
270
    if (std::find(newbies.begin(), newbies.end(), it) == newbies.end())
 
271
      continue;
 
272
    
 
273
    std::string pos;
 
274
    bool before;
 
275
    
 
276
    impl::GetSignalAddedInfo(favorites_, newbies , it, pos, before);
 
277
    favorite_added.emit(it, pos, before);
 
278
  }
 
279
                     
 
280
  for (auto it : impl::GetRemoved(old, favorites_))
 
281
  {
 
282
    favorite_removed.emit(it); 
 
283
  }
 
284
  
 
285
  if (impl::NeedToBeReordered(old, favorites_))
 
286
    reordered.emit();
 
287
 
261
288
}
262
289
 
263
290
namespace