~azzar1/unity/proper-reboot

« back to all changes in this revision

Viewing changes to plugins/unityshell/src/DeviceLauncherIcon.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:
43
43
 
44
44
}
45
45
 
46
 
DeviceLauncherIcon::DeviceLauncherIcon(Launcher* launcher, GVolume* volume)
47
 
  : SimpleLauncherIcon(launcher)
 
46
DeviceLauncherIcon::DeviceLauncherIcon(GVolume* volume)
 
47
  : SimpleLauncherIcon()
48
48
  , volume_(volume)
49
49
  , device_file_(g_volume_get_identifier(volume_, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE))
50
50
  , gdu_device_(get_device_for_device_file(device_file_))
51
 
{  
 
51
{
52
52
  DevicesSettings::GetDefault().changed.connect(sigc::mem_fun(this, &DeviceLauncherIcon::OnSettingsChanged));
53
53
 
54
54
  // Checks if in favourites!
57
57
  DeviceList::iterator pos = std::find(favorites.begin(), favorites.end(), uuid.Str());
58
58
 
59
59
  keep_in_launcher_ = pos != favorites.end();
60
 
  
 
60
 
61
61
  UpdateDeviceIcon();
62
62
  UpdateVisibility();
63
63
}
70
70
 
71
71
  tooltip_text = name.Str();
72
72
  icon_name = icon_string.Str();
73
 
  
 
73
 
74
74
  SetIconType(TYPE_DEVICE);
75
75
  SetQuirk(QUIRK_RUNNING, false);
76
76
}
81
81
  return g_volume_can_eject(volume_);
82
82
}
83
83
 
84
 
nux::Color DeviceLauncherIcon::BackgroundColor()
85
 
{
86
 
  return nux::Color(0xFF333333);
87
 
}
88
 
 
89
 
nux::Color DeviceLauncherIcon::GlowColor()
90
 
{
91
 
  return nux::Color(0xFF333333);
92
 
}
93
 
 
94
84
std::list<DbusmenuMenuitem*> DeviceLauncherIcon::GetMenus()
95
85
{
96
86
  std::list<DbusmenuMenuitem*> result;
97
87
  DbusmenuMenuitem* menu_item;
98
88
  glib::Object<GDrive> drive(g_volume_get_drive(volume_));
99
89
 
100
 
  // "Lock to launcher"/"Unlock from launcher" item
 
90
  // "Lock to Launcher"/"Unlock from Launcher" item
101
91
  if (DevicesSettings::GetDefault().GetDevicesOption() == DevicesSettings::ONLY_MOUNTED
102
92
      && drive && !g_drive_is_media_removable (drive))
103
93
  {
104
94
    menu_item = dbusmenu_menuitem_new();
105
95
 
106
 
    dbusmenu_menuitem_property_set(menu_item, DBUSMENU_MENUITEM_PROP_LABEL, !keep_in_launcher_ ? _("Lock to launcher") : _("Unlock from launcher"));
 
96
    dbusmenu_menuitem_property_set(menu_item, DBUSMENU_MENUITEM_PROP_LABEL, !keep_in_launcher_ ? _("Lock to Launcher") : _("Unlock from Launcher"));
107
97
    dbusmenu_menuitem_property_set_bool(menu_item, DBUSMENU_MENUITEM_PROP_ENABLED, true);
108
98
    dbusmenu_menuitem_property_set_bool(menu_item, DBUSMENU_MENUITEM_PROP_VISIBLE, true);
109
 
    
 
99
 
110
100
    g_signal_connect(menu_item, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED,
111
101
                     G_CALLBACK(&DeviceLauncherIcon::OnTogglePin), this);
112
102
 
113
103
    result.push_back(menu_item);
114
104
  }
115
 
  
 
105
 
116
106
  // "Open" item
117
107
  menu_item = dbusmenu_menuitem_new();
118
108
 
122
112
 
123
113
  g_signal_connect(menu_item, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED,
124
114
                   G_CALLBACK(&DeviceLauncherIcon::OnOpen), this);
125
 
                   
 
115
 
126
116
  result.push_back(menu_item);
127
 
  
 
117
 
128
118
  // "Format" item
129
119
  if (gdu_device_ && !gdu_device_is_optical_disc(gdu_device_))
130
120
  {
131
121
    menu_item = dbusmenu_menuitem_new();
132
122
 
 
123
    // TRANSLATORS: This refers to the action of formatting a device
133
124
    dbusmenu_menuitem_property_set(menu_item, DBUSMENU_MENUITEM_PROP_LABEL, _("Format..."));
134
125
    dbusmenu_menuitem_property_set_bool(menu_item, DBUSMENU_MENUITEM_PROP_ENABLED, true);
135
126
    dbusmenu_menuitem_property_set_bool(menu_item, DBUSMENU_MENUITEM_PROP_VISIBLE, true);
136
127
 
137
128
    g_signal_connect(menu_item, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED,
138
129
                     G_CALLBACK(&DeviceLauncherIcon::OnFormat), this);
139
 
                     
 
130
 
140
131
    result.push_back(menu_item);
141
132
  }
142
133
 
143
134
  // "Eject" item
144
135
  if (drive && g_drive_can_eject(drive))
145
 
  {    
 
136
  {
146
137
    menu_item = dbusmenu_menuitem_new();
147
 
    
 
138
 
148
139
    GList *list = g_drive_get_volumes(drive);
149
140
    if (list != NULL)
150
141
    {
152
143
        dbusmenu_menuitem_property_set(menu_item, DBUSMENU_MENUITEM_PROP_LABEL, _("Eject"));
153
144
      else
154
145
        dbusmenu_menuitem_property_set(menu_item, DBUSMENU_MENUITEM_PROP_LABEL, _("Eject parent drive"));
155
 
        
 
146
 
156
147
      g_list_free_full(list, g_object_unref);
157
148
    }
158
 
    
 
149
 
159
150
    dbusmenu_menuitem_property_set_bool(menu_item, DBUSMENU_MENUITEM_PROP_ENABLED, true);
160
151
    dbusmenu_menuitem_property_set_bool(menu_item, DBUSMENU_MENUITEM_PROP_VISIBLE, true);
161
152
 
169
160
  if (drive && g_drive_can_stop(drive))
170
161
  {
171
162
    menu_item = dbusmenu_menuitem_new();
172
 
    
 
163
 
173
164
    GList *list = g_drive_get_volumes(drive);
174
165
    if (list != NULL)
175
166
    {
177
168
        dbusmenu_menuitem_property_set(menu_item, DBUSMENU_MENUITEM_PROP_LABEL, _("Safely remove"));
178
169
      else
179
170
        dbusmenu_menuitem_property_set(menu_item, DBUSMENU_MENUITEM_PROP_LABEL, _("Safely remove parent drive"));
180
 
        
 
171
 
181
172
      g_list_free_full(list, g_object_unref);
182
173
    }
183
174
 
186
177
 
187
178
    g_signal_connect(menu_item, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED,
188
179
                     G_CALLBACK(&DeviceLauncherIcon::OnDriveStop), this);
189
 
                     
 
180
 
190
181
    result.push_back(menu_item);
191
182
  }
192
183
 
252
243
{
253
244
  SimpleLauncherIcon::ActivateLauncherIcon(arg);
254
245
  SetQuirk(QUIRK_STARTING, true);
255
 
  
 
246
 
256
247
  glib::Object<GMount> mount(g_volume_get_mount(volume_));
257
248
 
258
249
  if (G_IS_MOUNT(mount.RawPtr()))
292
283
                                      DeviceLauncherIcon* self)
293
284
{
294
285
  if (g_volume_eject_with_operation_finish(self->volume_, result, NULL))
295
 
  {    
 
286
  {
296
287
    IconLoader::GetDefault().LoadFromGIconString(self->icon_name(), 48,
297
288
                                                 sigc::mem_fun(self, &DeviceLauncherIcon::ShowNotification));
298
289
  }
299
290
}
300
291
 
301
 
void DeviceLauncherIcon::ShowNotification(std::string const& icon_name, 
 
292
void DeviceLauncherIcon::ShowNotification(std::string const& icon_name,
302
293
                                          unsigned size,
303
294
                                          GdkPixbuf* pixbuf)
304
295
{
305
 
  
 
296
 
306
297
  glib::String name(g_volume_get_name(volume_));
307
298
  glib::Object<NotifyNotification> notification(notify_notification_new(name,
308
299
                                                                        _("The drive has been successfully ejected"),
309
300
                                                                        NULL));
310
 
                                                                        
 
301
 
311
302
  notify_notification_set_hint(notification,
312
303
                               "x-canonical-private-synchronous",
313
304
                               g_variant_new_boolean(TRUE));
314
 
  
 
305
 
315
306
  if(GDK_IS_PIXBUF(pixbuf))
316
307
    notify_notification_set_image_from_pixbuf(notification, pixbuf);
317
 
    
 
308
 
318
309
  notify_notification_show(notification, NULL);
319
310
}
320
311
 
335
326
                                     DeviceLauncherIcon* self)
336
327
{
337
328
  glib::String uuid(g_volume_get_identifier(self->volume_, G_VOLUME_IDENTIFIER_KIND_UUID));
338
 
  
 
329
 
339
330
  self->keep_in_launcher_ = !self->keep_in_launcher_;
340
331
 
341
332
  if (!self->keep_in_launcher_)
344
335
    glib::Object<GMount> mount(g_volume_get_mount(self->volume_));
345
336
 
346
337
    if (!mount)
347
 
      self->SetQuirk(QUIRK_VISIBLE, false); 
 
338
      self->SetQuirk(QUIRK_VISIBLE, false);
348
339
 
349
340
    // Remove from favorites
350
341
    if (!uuid.Str().empty())
369
360
                                  DeviceLauncherIcon* self)
370
361
{
371
362
  glib::Error error;
372
 
  
 
363
 
373
364
  gchar const* args[] = { "/usr/lib/gnome-disk-utility/gdu-format-tool",
374
365
                          "--device-file",
375
366
                          self->device_file_.Value(),
376
367
                          NULL};
377
 
                          
 
368
 
378
369
  g_spawn_async(NULL, // working dir
379
370
                const_cast<gchar **>(args),
380
371
                NULL, // envp
383
374
                NULL, // user_data
384
375
                NULL, // GPid *child_pid
385
376
                &error);
386
 
                
 
377
 
387
378
  if (error)
388
379
  {
389
380
    LOG_WARNING(logger) << "Error launching " << args[0] << ": " << error;
408
399
void DeviceLauncherIcon::Unmount()
409
400
{
410
401
  glib::Object<GMount> mount(g_volume_get_mount(volume_));
411
 
  
 
402
 
412
403
  if (mount)
413
404
  {
414
405
    glib::Object<GMountOperation> op(gtk_mount_operation_new(NULL));
469
460
      else if (visibility < 0)
470
461
      {
471
462
        glib::Object<GMount> mount(g_volume_get_mount(volume_));
472
 
        SetQuirk(QUIRK_VISIBLE, mount.RawPtr() != NULL); 
 
463
        SetQuirk(QUIRK_VISIBLE, mount.RawPtr() != NULL);
473
464
      }
474
465
      else
475
466
      {
476
 
        SetQuirk(QUIRK_VISIBLE, visibility); 
 
467
        SetQuirk(QUIRK_VISIBLE, visibility);
477
468
      }
478
469
      break;
479
470
    case DevicesSettings::ALWAYS:
494
485
  UpdateVisibility();
495
486
}
496
487
 
 
488
std::string DeviceLauncherIcon::GetName() const
 
489
{
 
490
  return "DeviceLauncherIcon";
 
491
}
 
492
 
497
493
namespace
498
494
{
499
495