summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornic80 <joe_c_moi@yahoo.fr>2020-05-30 14:15:26 +0200
committerNicolas Lécureuil <neoclust@mageia.org>2020-06-02 10:55:39 +0200
commitea3b78d47a1b4a6f5d7419fd414edbe59ad35bca (patch)
tree22f8746929b88c4467b1ffad16c66a208d38e08c
parentd4a0a65eb198dab6b88e954b2a998482b80aa512 (diff)
downloaddraksnapshot-ea3b78d47a1b4a6f5d7419fd414edbe59ad35bca.tar
draksnapshot-ea3b78d47a1b4a6f5d7419fd414edbe59ad35bca.tar.gz
draksnapshot-ea3b78d47a1b4a6f5d7419fd414edbe59ad35bca.tar.bz2
draksnapshot-ea3b78d47a1b4a6f5d7419fd414edbe59ad35bca.tar.xz
draksnapshot-ea3b78d47a1b4a6f5d7419fd414edbe59ad35bca.zip
Get a working interface
-rw-r--r--[-rwxr-xr-x]draksnapshot-applet46
-rw-r--r--[-rwxr-xr-x]draksnapshot-config67
-rw-r--r--[-rwxr-xr-x]lib/MDV/Snapshot/Hal.pm89
3 files changed, 146 insertions, 56 deletions
diff --git a/draksnapshot-applet b/draksnapshot-applet
index 4a2012a..b5074ec 100755..100644
--- a/draksnapshot-applet
+++ b/draksnapshot-applet
@@ -34,16 +34,16 @@ use MDV::Snapshot::Hal;
BEGIN { unshift @::textdomains, 'draksnapshot' }
-use mygtk2 qw(gtknew); #- do not import gtkadd which conflicts with ugtk2 version
-use ugtk2 qw(:all);
+use mygtk3 qw(gtknew); #- do not import gtkadd which conflicts with ugtk2 version
+use ugtk3 qw(:all);
use lib qw(/usr/lib/libDrakX/drakfirsttime);
-use Gtk2::Notify '-init', 'draksnapshot';
+use Gtk3::Notify '-init', 'draksnapshot';
if (my $pid = is_running('draksnapshot-ap')) {
die "draksnapshot-applet already running ($pid)\n";
}
-ugtk2::add_icon_path("/usr/share/draksnapshot/pixmaps/");
+ugtk3::add_icon_path("/usr/share/draksnapshot/pixmaps/");
my $menu;
@@ -75,7 +75,7 @@ my %actions = (
# create status icon:
-my $icon = Gtk2::StatusIcon->new;
+my $icon = Gtk3::StatusIcon->new;
$icon->signal_connect(popup_menu => sub {
my ($_icon, $button, $time) = @_;
$menu and $menu->popup(undef, undef, undef, undef, $button, $time);
@@ -129,7 +129,7 @@ if ($dbus && $do) {
# make icon actually visible so that notification gots proper positionning:
gtkflush();
my $bubble =
- Gtk2::Notify->new(N("Error. Service disabled."),
+ Gtk3::Notify::Notification->new(N("Error. Service disabled."),
join("\n",
formatAlaTeX(N("Error while initializing DBus:")),
$dbus_error,
@@ -141,10 +141,10 @@ if ($dbus && $do) {
my $timeout_bubble = 5000;
$bubble->set_timeout($timeout_bubble);
eval { $bubble->show };
- Glib::Timeout->add($timeout_bubble + 100, sub { Gtk2->exit; exit(1) });
+ Glib::Timeout->add($timeout_bubble + 100, sub { Gtk3::exit; exit(1) });
0;
});
- Gtk2->main;
+ Gtk3->main;
exit(1);
}
@@ -165,10 +165,10 @@ $SIG{CHLD} = \&harvester;
run_program::raw({ detach => 1 }, 'ionice', '-p', $$, '-n7');
-$do and $do->set_gtk2_watch;
-Gtk2->main;
+$do and $do->set_gtk3_watch;
+Gtk3->main;
-ugtk2::exit(0);
+ugtk3::exit(0);
my $config_pid;
@@ -203,7 +203,7 @@ sub refresh_gui {
}
sub configure() {
- $config_pid = fork_exec('/usr/sbin/draksnapshot-config');
+ $config_pid = fork_exec('/usr/bin/draksnapshot-config');
go2State('config_in_progress');
}
@@ -230,29 +230,29 @@ sub setState {
my ($state_type) = @_;
my $checkme;
my $arr = $state{$state_type}{menu};
- $icon->set_tooltip(formatAlaTeX(translate($state{$state_type}{tt}[0])));
+ $icon->set_tooltip_text(formatAlaTeX(translate($state{$state_type}{tt}[0])));
$icon->set_visible($state_type ne 'okay');
gtkflush(); # so that bubbles are displayed on right icon
select(undef, undef, undef, 0.1); #- hackish :-(
- if ($state{$state_type}{tt}[0] && $icon->isa('Gtk2::StatusIcon') && !$state{$state_type}{do_not_use_bubble}) {
- my $bubble = Gtk2::Notify->new(N("Info"), formatAlaTeX(translate($state{$state_type}{tt}[0])) . "\n",
+ if ($state{$state_type}{tt}[0] && $icon->isa('Gtk3::StatusIcon') && !$state{$state_type}{do_not_use_bubble}) {
+ my $bubble = Gtk3::Notify::Notification->new(N("Info"), formatAlaTeX(translate($state{$state_type}{tt}[0])) . "\n",
'/usr/share/icons/draksnapshot.png');
$bubble->set_timeout(5000);
eval { $bubble->show };
}
- my $menu = Gtk2::Menu->new;
+ my $menu = Gtk3::Menu->new;
foreach (@$arr) {
- $menu->append(gtksignal_connect(gtkshow(Gtk2::MenuItem->new_with_label($actions{$_}{name})), activate => $actions{$_}{launch}));
+ $menu->append(gtksignal_connect(gtkshow(Gtk3::MenuItem->new_with_label($actions{$_}{name})), activate => $actions{$_}{launch}));
}
- $menu->append(gtkshow(Gtk2::SeparatorMenuItem->new));
+ $menu->append(gtkshow(Gtk3::SeparatorMenuItem->new));
$menu->append(
gtksignal_connect(
- gtkshow(Gtk2::MenuItem->new_with_label(N("About..."))),
+ gtkshow(Gtk3::MenuItem->new_with_label(N("About..."))),
activate => sub {
- my $ver = 1; # automatically set from spec file
+ my $ver = '0.20.3-18.mga7'; # automatically set from spec file
my $w = gtknew('AboutDialog', name => N("DrakSnapshot %s", $ver),
copyright => N("Copyright (C) %s by Mandriva", '2008'),
license => join('', cat_('/usr/share/common-licenses/GPL')),
@@ -272,9 +272,9 @@ sub setState {
return 1;
}));
- $menu->append(gtksignal_connect(gtkset_active($checkme = Gtk2::CheckMenuItem->new_with_label(N("Always launch on startup")), shouldStart()), toggled => sub { setAutoStart(uc(bool2text($checkme->get_active))) }));
+ $menu->append(gtksignal_connect(gtkset_active($checkme = Gtk3::CheckMenuItem->new_with_label(N("Always launch on startup")), shouldStart()), toggled => sub { setAutoStart(uc(bool2text($checkme->get_active))) }));
$checkme->show;
- $menu->append(gtksignal_connect(gtkshow(Gtk2::MenuItem->new_with_label(N("Quit"))), activate => sub { mainQuit() }));
+ $menu->append(gtksignal_connect(gtkshow(Gtk3::MenuItem->new_with_label(N("Quit"))), activate => sub { mainQuit() }));
$menu;
}
@@ -300,5 +300,5 @@ sub setAutoStart {
}
sub mainQuit() {
- Gtk2->main_quit;
+ Gtk3->main_quit;
}
diff --git a/draksnapshot-config b/draksnapshot-config
index 8a6eb60..9982fe1 100755..100644
--- a/draksnapshot-config
+++ b/draksnapshot-config
@@ -28,7 +28,7 @@ use standalone; #- warning, standalone must be loaded very first, for 'expla
use common;
use interactive;
use MDV::Snapshot::Common;
-#use MDV::Snapshot::Hal;
+use MDV::Snapshot::Hal;
# i18n: IMPORTANT: to get correct namespace (drakconf instead of libDrakX)
BEGIN { unshift @::textdomains, 'draksnapshot' }
@@ -101,7 +101,7 @@ my @menu_items = (
{ path => N("/_Help"), item_type => '<LastBranch>' },
{ path => N("/Help/_About...") }
);
-my $_menubar = $::isEmbedded ? ugtk2::create_factory_menu($my_win->{rwindow}, @menu_items) : undef;
+my $_menubar = $::isEmbedded ? Gtk3::MenuBar->new($my_win->{rwindow}, @menu_items) : undef;
#my $_menubar = create_factory_menu($my_win->{rwindow}, @menu_items);
######### menus end
@@ -111,9 +111,13 @@ my $where;
# if not configured, just default where will be mounted the discs by HAL:
if (!$backup_directory || $::testing) {
my $dbus = get_system_bus();
- if ($dbus) {
- my @discs = map { $_->GetProperty('volume.mount_point') } eval { find_removable_volumes($dbus) };
- $backup_directory = $discs[0];
+ if ($dbus) {#decting by dbus is broken
+ # my @discs = map { $_ } eval { find_removable_volumes($dbus) };
+ # $backup_directory = $discs[0];
+ }
+ if (!$backup_directory) #not defined either by common.pm, rsnapshot.conf, or hal/udisks2 (current situation); Set a dummy path to be changed by user
+ {
+ $backup_directory="~/not_existing_path";
}
}
@@ -180,6 +184,7 @@ gtkadd($my_win->{window},
]),
]),
0, gtknew('HButtonBox', layout => 'end', border_width => 5, spacing => 5, children_loose => [
+ gtknew('Button', text => N("Restore"), clicked => \&restore),
gtknew('Button', text => N("Apply"), clicked => \&save),
gtknew('Button', text => $::isEmbedded ? N("Cancel") : N("Close"), clicked => sub { quit() })
])
@@ -227,33 +232,44 @@ sub add {
my $dlg = gtknew('Dialog', transient_for => $my_win->{real_window}, title => N("Add"));
my $browse = gtknew('Button', text => N("browse"));
my $file = gtknew('Entry', $o_iter ? (text => $model->get($o_iter, 1)) : ());
-
my $alrd_exsts = defined $o_iter;
+ my $filename_choice;
$browse->signal_connect(clicked => sub {
- my $file_dlg = Gtk3::FileSelection->new(N("Path selection"));
+ my $file_dlg = Gtk3::FileChooserDialog->new(N("Path selection"),$dlg, GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,N("Cancel") => GTK_RESPONSE_CANCEL,N("OK") => GTK_RESPONSE_OK);
$file_dlg->set_modal(1);
$file_dlg->set_transient_for($dlg);
$file_dlg->show;
$file_dlg->set_filename($file->get_text);
- $file_dlg->cancel_button->signal_connect(clicked => sub { $file_dlg->destroy });
- $file_dlg->ok_button->signal_connect(clicked => sub {
- $file->set_text($file_dlg->get_filename);
- $file_dlg->destroy;
- });
- });
-
- gtkpack_($dlg->vbox,
+ my $answer_add=$file_dlg->run;
+
+ if ( $answer_add eq 'cancel' )
+ {
+ $file_dlg->destroy;
+ }
+ else
+ {
+ if ( $answer_add eq 'ok' ){
+ $filename_choice=$file_dlg->get_filename;
+ $file->set_text($file_dlg->get_filename);
+ $file_dlg->destroy;
+ }
+ }
+ });
+
+
+ gtkpack_($dlg->get_content_area(),
0, gtknew('Title2', label => N("Path")),
0, gtknew('HBox', border_width => 18, children => [
- 1, $file,
- 0, $browse
- ]),
- );
+ 1, $file,
+ 0, $browse
+ ]),
+ );
+
#$dlg->set_has_separator(0);
- gtkadd($dlg->action_area,
+ gtkadd($dlg->get_action_area,
create_okcancel(my $w =
{
cancel_clicked => sub { $dlg->destroy },
@@ -280,7 +296,7 @@ sub add {
}
sub save() {
- save_keyword('interval', map {
+ save_keyword('retain', map {
my $val = $default_intervals{$_};
if_($val, join("\t", 'retain', $_, $val));
} @ordered_intervals);
@@ -300,6 +316,15 @@ sub save() {
generate_cron_entry();
}
+sub fork_exec {
+ my $pid = run_program::raw({ detach => 1 }, @_);
+ return $pid;
+}
+
+sub restore() {
+ fork_exec('/usr/sbin/draksnapshot-restore');
+}
+
sub save_keyword {
my ($keyword, @values) = @_;
my ($removed, $done);
diff --git a/lib/MDV/Snapshot/Hal.pm b/lib/MDV/Snapshot/Hal.pm
index 18736ae..51208c6 100755..100644
--- a/lib/MDV/Snapshot/Hal.pm
+++ b/lib/MDV/Snapshot/Hal.pm
@@ -32,9 +32,17 @@ 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';
+our $hal_dn = 'org.freedesktop.UDisks2';
+our $hal_manager = 'org.freedesktop.DBus.ObjectManager';
+our $manager_path = '/org/freedesktop/UDisks2';
+our $dbus_object_manager ='org.freedesktop.DBus.ObjectManager';
+our $block_devices='org.freedesktop.UDisks2.Block';
+our $path_to_drives='/org/freedesktop/UDisks2/drives';
+our $path_to_drive_prop='org.freedesktop.UDisks2.Drive';
+our $path_to_block_devices='/org/freedesktop/UDisks2/block_devices';
+our $path_to_block_prop_part='org.freedesktop.UDisks2.Partition';
+our $path_to_block_prop_file='org.freedesktop.UDisks2.Filesystem';
+our $path_to_block_prop_block='org.freedesktop.UDisks2.Block';
sub get_system_bus() {
eval { dbus_object::system_bus() };
@@ -43,19 +51,76 @@ sub get_system_bus() {
sub is_proper_device {
my ($device, $o_is_first_check) = @_; # perl_checker: $device = Net::DBus::RemoteObject->new
- 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;
+ #my $device_name = $device->QueryCapability('block') && $device->GetProperty('block.device');
+ #return if !$device_name;
+ my $bool=0;
+ my @is_mounted;
+ if ( grep /^*[0-9]$/, $device ) {
+
+ my ($dbus) = Net::DBus->system;
+ my $service = $dbus->get_service($hal_dn);
+ my $block_device_properties_object= $service->get_object($device,'org.freedesktop.DBus.Properties');
+ my $is_read_only=$block_device_properties_object->Get($path_to_block_prop_block,"ReadOnly");
+ print("Read only status of $device is :$is_read_only \n");
+ if ( $is_read_only = "false") { # device is not readonly
+ my $is_zero_size=$block_device_properties_object->Get($path_to_block_prop_block,"Size");
+ print("Size of $device is : $is_zero_size \n");
+ if ( $is_zero_size > 0){
+ @is_mounted=$block_device_properties_object->Get($path_to_block_prop_file,"MountPoints");
+ if (@is_mounted != []){
+ print("Block Device $device is proper for backups \n");
+ $bool = 1; }
+ else
+ {
+ print("Block Device $device is NOT proper for backups \n");
+ $bool = 0;}
+ }
+ }
+ }
+
+ #return $o_is_first_check ? $bool && $device_name && cat_('/media/.hal-mtab') =~ m!^$device_name\s!sg : $bool;
+ #print("Value returned by is_proper_device: $bool \n");
+ return $bool && @is_mounted;
}
sub find_removable_volumes {
+ #my ($dbus) = Net::DBus->system;
my ($dbus) = @_; # perl_checker: $dbus = Net::DBus->new
- my $hal = $dbus->get_service($hal_dn); # perl_checker: $dbus = Net::DBus->new
- my $manager = $hal->get_object($manager_path, $hal_manager); # perl_checker: $manager = Net::DBus::RemoteObject
+ my $service = $dbus->get_service($hal_dn); # perl_checker: $dbus = Net::DBus->new
+ my $manager = $service->get_object($manager_path,$hal_manager); # perl_checker: $manager = Net::DBus::RemoteObject
+ my @eligible_drives;#To fill a list of drive that have the property MediaRemovable
+ my @eligible_block_devices;
+ my @drives= (grep /\/org\/freedesktop\/UDisks2\/drives\//,%{$manager->GetManagedObjects}); # To get only the list of present drives on computer whatever they are
+ my @block_devices=(grep /\/org\/freedesktop\/UDisks2\/block_devices\//,%{$manager->GetManagedObjects}); # To get the block_devices list on system to check against the drives
+ for(my $k=0;$k < scalar @drives;$k= $k+1){
+ print ("Drive: @drives[$k]\n");
+ }
- grep { is_proper_device($_, 1) } map { $hal->get_object($_, "$hal_dn.Device") } @{$manager->GetAllDevices};
-}
+ for(my $i=0;$i < scalar @block_devices;$i= $i+1){
+ print ("block_device: @block_devices[$i]\n");
+ }
+ for (my $i=0;$i < scalar @drives;$i= $i+1){
+ my $drives_properties_object= $service->get_object(@drives[$i],'org.freedesktop.DBus.Properties');
+ my $is_removable=$drives_properties_object->Get($path_to_drive_prop,"MediaRemovable");# testing is drive is removable
+ if ($is_removable) {
+ push(@eligible_drives,@drives[$i]); # drive is removable; adding it to list to test block_device against
+ print("Removable device: @drives[$i] added \n");
+ }
+ for (my $j=0;$j < scalar @block_devices;$j= $j+1){
+ my $block_device_properties_object= $service->get_object(@block_devices[$j],'org.freedesktop.DBus.Properties');
+ my $get_drive_from_block_device=$block_device_properties_object->Get($path_to_block_prop_block,"Drive");
+ if (grep /^$get_drive_from_block_device$/,@eligible_drives) {
+ print("testing:@block_devices[$j], from $get_drive_from_block_device\n");
+ push(@eligible_block_devices,@block_devices[$j]);
+ is_proper_device(@block_devices[$j], 1);
+ }
+ }
+ }
+ #grep { is_proper_device($_, 1) } map { $service->get_object($_, "$block_devices") } @eligible_block_devices;
+ #grep { is_proper_device($_, 1) } map { $service->get_object($_, "$block_devices") } @{$manager->GetManagedObjects};
+ }
+
+#my $dbus_test=get_system_bus;
+#$dbus_test.find_removable_volumes;
1;