summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortv <tv@99302b65-d5f7-0310-b3dd-f8cd6f4e3d94>2008-09-29 16:33:45 +0000
committertv <tv@99302b65-d5f7-0310-b3dd-f8cd6f4e3d94>2008-09-29 16:33:45 +0000
commit22a09ee966bb5d0c043be047721b03d8673f53fa (patch)
treeb8930ca44d66de8c02709e399355c41e45c7897f
parentb924be1403c5be6e452e41ec817a9b844262e31b (diff)
downloaddraksnapshot-22a09ee966bb5d0c043be047721b03d8673f53fa.tar
draksnapshot-22a09ee966bb5d0c043be047721b03d8673f53fa.tar.gz
draksnapshot-22a09ee966bb5d0c043be047721b03d8673f53fa.tar.bz2
draksnapshot-22a09ee966bb5d0c043be047721b03d8673f53fa.tar.xz
draksnapshot-22a09ee966bb5d0c043be047721b03d8673f53fa.zip
split Hal code so that it can be reused in configurator
git-svn-id: http://svn.mandriva.com/svn/soft/draksnapshot/trunk@247028 99302b65-d5f7-0310-b3dd-f8cd6f4e3d94
-rwxr-xr-xdraksnapshot-applet21
-rwxr-xr-xlib/MDV/Snapshot/Hal.pm60
2 files changed, 63 insertions, 18 deletions
diff --git a/draksnapshot-applet b/draksnapshot-applet
index 32100f0..e50c042 100755
--- a/draksnapshot-applet
+++ b/draksnapshot-applet
@@ -29,7 +29,7 @@ use interactive;
use common;
use run_program;
use detect_devices;
-use dbus_object;
+use MDV::Snapshot::Hal;
use Gtk2::Pango;
@@ -87,11 +87,8 @@ $icon->signal_connect(activate => \&configure);
$icon->set_from_pixbuf(gtkcreate_pixbuf('draksnapshot'));
-my $hal_dn = 'org.freedesktop.Hal';
-my $hal_manager = "$hal_dn.Manager";
-my $manager_path = '/org/freedesktop/Hal/Manager';
-my $dbus = eval { dbus_object::system_bus() };
+my $dbus = get_system_bus();
my $dbus_error = $@;
@@ -207,20 +204,8 @@ sub configure() {
go2State('config_in_progress');
}
-sub is_proper_device {
- my ($device, $o_is_first_check) = @_;
- my $device_name = $device->QueryCapability('block') && $device->GetProperty('block.device');
- return if !$device_name;
- my $bool = $device->QueryCapability('volume') && !$device->GetProperty('volume.is_disc') &&
- $device->GetProperty('volume.is_mounted');
- return $o_is_first_check ? $bool && $device_name && cat_('/media/.hal-mtab') =~ m!^$device_name\s!sg : $bool;
-}
-
sub firstCheck() {
- my $hal = $dbus->get_service($hal_dn);
- my $manager = $hal->get_object($manager_path, $hal_manager);
-
- my @discs = grep { is_proper_device($_, 1) } map { $hal->get_object($_, "$hal_dn.Device") } @{$manager->GetAllDevices};
+ my @discs = find_removable_volumes($dbus);
go2State(@discs ? 'disk_found' : 'okay');
}
diff --git a/lib/MDV/Snapshot/Hal.pm b/lib/MDV/Snapshot/Hal.pm
new file mode 100755
index 0000000..374f771
--- /dev/null
+++ b/lib/MDV/Snapshot/Hal.pm
@@ -0,0 +1,60 @@
+package MDV::Snapshot::Hal;
+
+################################################################################
+# Backup Configuration Tool #
+# #
+# Copyright (C) 2008 Mandriva #
+# #
+# Thierry Vignaud <tvignaud at mandriva dot com> #
+# #
+# This program is free software; you can redistribute it and/or modify #
+# it under the terms of the GNU General Public License Version 2 as #
+# published by the Free Software Foundation. #
+# #
+# This program is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
+# GNU General Public License for more details. #
+# #
+# You should have received a copy of the GNU General Public License #
+# along with this program; if not, write to the Free Software #
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #
+################################################################################
+
+
+use strict;
+use lib qw(/usr/lib/libDrakX);
+use MDK::Common;
+use dbus_object;
+
+use Exporter;
+our @ISA = qw(Exporter);
+our @EXPORT = qw($hal_dn $hal_manager $manager_path find_removable_volumes get_system_bus is_proper_device);
+
+our $hal_dn = 'org.freedesktop.Hal';
+our $hal_manager = "$hal_dn.Manager";
+our $manager_path = '/org/freedesktop/Hal/Manager';
+
+sub get_system_bus() {
+ eval { dbus_object::system_bus() };
+}
+
+
+sub is_proper_device {
+ my ($device, $o_is_first_check) = @_;
+ my $device_name = $device->QueryCapability('block') && $device->GetProperty('block.device');
+ return if !$device_name;
+ my $bool = $device->QueryCapability('volume') && !$device->GetProperty('volume.is_disc') &&
+ $device->GetProperty('volume.is_mounted');
+ return $o_is_first_check ? $bool && $device_name && cat_('/media/.hal-mtab') =~ m!^$device_name\s!sg : $bool;
+}
+
+sub find_removable_volumes {
+ my ($dbus) = @_;
+ my $hal = $dbus->get_service($hal_dn);
+ my $manager = $hal->get_object($manager_path, $hal_manager);
+
+ grep { is_proper_device($_, 1) } map { $hal->get_object($_, "$hal_dn.Device") } @{$manager->GetAllDevices};
+}
+
+1;