~ubuntu-branches/ubuntu/oneiric/unity/oneiric

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2011-08-01 19:53:15 UTC
  • mfrom: (1.1.49 upstream)
  • Revision ID: james.westby@ubuntu.com-20110801195315-mrewa9g7ctnk41oh
Tags: 4.6.0-0ubuntu1
* New upstream release.
  - compiz crashed with SIGSEGV in __strlen_sse2() (LP: #814619)
  - PlacesHomeView::PlacesHomeView leaks memory (LP: #818450)
  - PluginAdapter::MaximizeIfBigEnough leaks memory (LP: #818477)
  - Launcher - Make Launcher left of screen reveal more responsive and less
    prone to false positives (LP: #765819)
  - Launcher - clicking on a App launcher icon incorrectly un-minimizes
    windows (LP: #783434)
  - Unity doesn't get any mouse wheel scroll event in Indicators InputArea
    (LP: #814574)
  - Unity launcher gets cluttered when having multiple partitions and/or
    external volumes attached (LP: #713423)
  - Unity panel menus and indicators slow to respond. Too much lag.
    (LP: #742664)
  - In Unity the distinction between GVolume, GDrive and GMount is a bit
    confusing. (LP: #799890)
  - Launcher - When a item is deleted by dragging to Trash, the trash should
    pulse once before the Launcher disappears (LP: #750311)
  - ccsm needs an option to change launcher opacity (LP: #815032)
  - add a ccsm option to hide volumes in launcher (LP: #794707)
  - scale plugin doesn't work as desired when "Click Desktop To Show
    Desktop" is true (LP: #810315)
  - mute/unmute sound when user clicks on sound applet using scroll button
    or middle mouse button (LP: #609860)
  - Secondary activate (i.e. middle click) support for indicators advanced
    usage (LP: #812933)
* debian/control:
  - dep on latest libunity-misc
  - dep on latest nux
  - add build-dep on libgnome-desktop-3-dev
* debian/rules:
  - bump libunity-core-4.0-4 shlib for ABI break
  - don't ship unity dialogs right now. Not ready for alpha quality
* distro-patch the grey to darker grey (until the blur is done in nux)
* Switch to dpkg-source 3.0 (quilt) format
* debian/patches/01_revert_removed_function_for_unity2d_to_build.patch:
  - revert a removed API making unity-2d not building

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2
2
/*
3
 
* Copyright (C) 2010 Canonical Ltd
4
 
*
5
 
* This program is free software: you can redistribute it and/or modify
6
 
* it under the terms of the GNU General Public License version 3 as
7
 
* published by the Free Software Foundation.
8
 
*
9
 
* This program is distributed in the hope that it will be useful,
10
 
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
* GNU General Public License for more details.
13
 
*
14
 
* You should have received a copy of the GNU General Public License
15
 
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
 
*
17
 
* Authored by: Andrea Azzarone <aazzarone@hotmail.it>
18
 
*/
 
3
 * Copyright (C) 2010 Canonical Ltd
 
4
 *
 
5
 * This program is free software: you can redistribute it and/or modify
 
6
 * it under the terms of the GNU General Public License version 3 as
 
7
 * published by the Free Software Foundation.
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 * GNU General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public License
 
15
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
16
 *
 
17
 * Authored by: Andrea Azzarone <aazzarone@hotmail.it>
 
18
 */
19
19
 
20
20
#include "DevicesSettings.h"
21
21
 
22
 
static DevicesSettings* _devices_settings = NULL;
 
22
#include <algorithm>
 
23
 
 
24
namespace unity {
 
25
 
 
26
namespace {
 
27
 
 
28
const char* SETTINGS_NAME = "com.canonical.Unity.Devices";
 
29
 
 
30
void on_settings_updated(GSettings* settings,
 
31
                         const gchar* key,
 
32
                         DevicesSettings* self);
 
33
 
 
34
} // anonymous namespace
 
35
 
 
36
DevicesSettings& DevicesSettings::GetDefault()
 
37
{
 
38
  static DevicesSettings instance;
 
39
  return instance;
 
40
}
23
41
 
24
42
DevicesSettings::DevicesSettings()
25
 
  : _settings(NULL),
26
 
    _raw_devices_option(1),
27
 
    _devices_option(ONLY_MOUNTED)
28
 
{
29
 
  _settings = g_settings_new("com.canonical.Unity.Devices");
30
 
  g_signal_connect(_settings, "changed",
31
 
                   (GCallback)(DevicesSettings::Changed), this);
32
 
  Refresh();
33
 
}
34
 
 
35
 
DevicesSettings::~DevicesSettings()
36
 
{
37
 
  g_object_unref(_settings);
38
 
}
39
 
 
40
 
void
41
 
DevicesSettings::Refresh()
42
 
{
43
 
  _raw_devices_option = g_settings_get_enum(_settings, "devices-option");
44
 
 
45
 
  _devices_option = (DevicesOption)_raw_devices_option;
46
 
 
47
 
  changed.emit(this);
48
 
}
49
 
 
50
 
void
51
 
DevicesSettings::Changed(GSettings* settings, char* key, DevicesSettings* self)
52
 
{
53
 
  self->Refresh();
54
 
}
55
 
 
56
 
DevicesSettings*
57
 
DevicesSettings::GetDefault()
58
 
{
59
 
  if (G_UNLIKELY(!_devices_settings))
60
 
    _devices_settings = new DevicesSettings();
61
 
 
62
 
  return _devices_settings;
63
 
}
64
 
 
65
 
DevicesSettings::DevicesOption
66
 
DevicesSettings::GetDevicesOption()
67
 
{
68
 
  return _devices_option;
69
 
}
 
43
  : settings_(g_settings_new(SETTINGS_NAME))
 
44
  , ignore_signals_(false)
 
45
  , devices_option_(ONLY_MOUNTED)
 
46
{
 
47
 
 
48
  g_signal_connect(settings_, "changed", G_CALLBACK(on_settings_updated), this);
 
49
 
 
50
  Refresh();
 
51
}
 
52
 
 
53
void DevicesSettings::Refresh()
 
54
{
 
55
  gchar** favs = g_settings_get_strv(settings_, "favorites");
 
56
 
 
57
  favorites_.clear();
 
58
 
 
59
  for (int i = 0; favs[i] != NULL; i++)
 
60
    favorites_.push_back(favs[i]);
 
61
 
 
62
  g_strfreev(favs);
 
63
}
 
64
 
 
65
void DevicesSettings::AddFavorite(std::string const& uuid)
 
66
{
 
67
  if (uuid.empty())
 
68
    return;
 
69
  
 
70
  favorites_.push_back(uuid);
 
71
 
 
72
  SaveFavorites(favorites_);
 
73
  Refresh();
 
74
}
 
75
 
 
76
void DevicesSettings::RemoveFavorite(std::string const& uuid)
 
77
{
 
78
  if (uuid.empty())
 
79
    return;
 
80
 
 
81
  DeviceList::iterator pos = std::find(favorites_.begin(), favorites_.end(), uuid);
 
82
  if (pos == favorites_.end())
 
83
    return;
 
84
 
 
85
  favorites_.erase(pos);
 
86
  SaveFavorites(favorites_);
 
87
  Refresh();
 
88
}
 
89
 
 
90
void DevicesSettings::SaveFavorites(DeviceList const& favorites)
 
91
{
 
92
  const int size = favorites.size();
 
93
  const char* favs[size + 1];
 
94
  favs[size] = NULL;
 
95
 
 
96
  int index = 0;
 
97
  for (DeviceList::const_iterator i = favorites.begin(), end = favorites.end();
 
98
       i != end; ++i, ++index)
 
99
  {
 
100
    favs[index] = i->c_str();
 
101
  }
 
102
 
 
103
  ignore_signals_ = true;
 
104
  if (!g_settings_set_strv(settings_, "favorites", favs))
 
105
    g_warning("Saving favorites failed.");
 
106
  ignore_signals_ = false;
 
107
}
 
108
 
 
109
 
 
110
void DevicesSettings::Changed(std::string const& key)
 
111
{
 
112
  if (ignore_signals_)
 
113
    return;
 
114
  
 
115
  Refresh();
 
116
  
 
117
  changed.emit();
 
118
}
 
119
 
 
120
void DevicesSettings::SetDevicesOption(DevicesOption devices_option)
 
121
{
 
122
  if (devices_option == devices_option_)
 
123
    return;
 
124
 
 
125
  devices_option_ = devices_option;
 
126
 
 
127
  changed.emit();
 
128
}
 
129
 
 
130
namespace {
 
131
 
 
132
void on_settings_updated(GSettings* settings,
 
133
                         const gchar* key,
 
134
                         DevicesSettings* self)
 
135
{
 
136
  if (settings and key) {
 
137
    self->Changed(key);
 
138
  }
 
139
}
 
140
 
 
141
} // anonymous namespace
 
142
 
 
143
} // namespace unity