aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatteo Pasotti <matteo.pasotti@gmail.com>2014-01-26 12:35:06 +0100
committerMatteo Pasotti <matteo.pasotti@gmail.com>2014-01-26 12:35:06 +0100
commit267ce4f56d85f1fd618d9c03daa0f3e0514dd8c6 (patch)
tree49bb28a50b1b759bf10cc98acb111bd912f3d87c
parente320a003f4d87921272c67d89acddd33c2602b0d (diff)
parentfec5ef4ddfa4a2772c6bd96f6b72b88a7c0bf57d (diff)
downloadcolin-keep-267ce4f56d85f1fd618d9c03daa0f3e0514dd8c6.tar
colin-keep-267ce4f56d85f1fd618d9c03daa0f3e0514dd8c6.tar.gz
colin-keep-267ce4f56d85f1fd618d9c03daa0f3e0514dd8c6.tar.bz2
colin-keep-267ce4f56d85f1fd618d9c03daa0f3e0514dd8c6.tar.xz
colin-keep-267ce4f56d85f1fd618d9c03daa0f3e0514dd8c6.zip
Merge branch 'master' of ssh://git.mageia.org/software/adminpanel
-rw-r--r--AdminPanel/AdminMouse.pm278
-rw-r--r--AdminPanel/Shared.pm113
-rw-r--r--categories.conf3
-rwxr-xr-xmodules/adminMouse13
4 files changed, 397 insertions, 10 deletions
diff --git a/AdminPanel/AdminMouse.pm b/AdminPanel/AdminMouse.pm
new file mode 100644
index 0000000..fecf1e2
--- /dev/null
+++ b/AdminPanel/AdminMouse.pm
@@ -0,0 +1,278 @@
+# vim: set et ts=4 sw=4:
+#*****************************************************************************
+#
+# Copyright (c) 2013 Angelo Naselli <anaselli@linux.it>
+# from drakx services
+#
+# 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.
+#
+#*****************************************************************************
+
+package AdminPanel::AdminMouse;
+
+#leaving them atm
+use lib qw(/usr/lib/libDrakX);
+
+# i18n: IMPORTANT: to get correct namespace (drakx-kbd-mouse-x11 instead of libDrakX)
+BEGIN { unshift @::textdomains, 'drakx-kbd-mouse-x11' }
+
+use common;
+use modules;
+use mouse;
+use c;
+
+use AdminPanel::Shared;
+
+use yui;
+use Moose;
+
+extends qw( Module );
+
+has '+icon' => (
+ default => "/usr/share/mcc/themes/default/mousedrake-mdk.png",
+);
+
+has '+name' => (
+ default => N("AdminMouse"),
+);
+
+sub start {
+ my $self = shift;
+
+ $self->_adminMouseDialog();
+}
+
+sub _getUntranslatedName {
+ my ($self, $name, $list) = @_;
+
+ foreach my $n (@{$list}) {
+ my @names = split(/\|/, $n);
+ for (my $lev=0; $lev < scalar(@names); $lev++) {
+ if (translate($names[$lev]) eq $name) {
+ return $names[$lev];
+ }
+ }
+ }
+
+ return undef;
+}
+
+
+sub _adminMouseDialog {
+ my $self = shift;
+
+ my $datavalue = "TEST";
+
+ my $appTitle = yui::YUI::app()->applicationTitle();
+
+ ## set new title to get it in dialog
+ yui::YUI::app()->setApplicationTitle($self->name);
+ ## set icon if not already set by external launcher
+ yui::YUI::app()->setApplicationIcon($self->icon);
+
+ my $factory = yui::YUI::widgetFactory;
+
+ my $dialog = $factory->createMainDialog;
+ my $vbox = $factory->createVBox( $dialog );
+ my $frame = $factory->createFrame ($vbox, N("Please choose your type of mouse."));
+ my $treeWidget = $factory->createTree($frame, "");
+
+ my $modules_conf = modules::any_conf->read;
+
+ my $mouse = mouse::read();
+
+ if (!$::noauto) {
+ my $probed_mouse = mouse::detect($modules_conf);
+ $mouse = $probed_mouse if !$mouse->{Protocol} || !$probed_mouse->{unsafe};
+ }
+
+ if (!$mouse || !$::auto) {
+ $mouse ||= mouse::fullname2mouse('Universal|Any PS/2 & USB mice');
+
+ my $prev = my $fullname = $mouse->{type} . '|' . $mouse->{name};
+ my $selected = $mouse->{name};
+
+ my $fullList = { list => [ mouse::_fullnames() ], items => [], separator => '|', val => \$fullname,
+ format => sub { join('|', map { translate($_) } split('\|', $_[0])) } } ;
+ my $i;
+
+ my $itemColl = new yui::YItemCollection;
+ my @items;
+ for ($i=0; $i<scalar(@{$fullList->{list}}); $i++) {
+ my @names = split(/\|/, $fullList->{list}[$i]);
+ for (my $lev=0; $lev < scalar(@names); $lev++) {
+ $names[$lev] = N($names[$lev]);
+ }
+ if ($i == 0 || $names[0] ne $items[0]->{label}) {
+ if ($i != 0) {
+ $itemColl->push($items[0]->{item});
+ push @{$fullList->{items}}, $items[-1]->{item};;
+ }
+ @items = undef;
+ my $item = new yui::YTreeItem ($names[0]);
+
+ if ($selected eq $self->_getUntranslatedName($item->label(), $fullList->{list})) {
+ $item->setSelected(1) ;
+ $item->setOpen(1);
+ my $parent = $item;
+ while($parent = $parent->parent()) {
+ $parent->setOpen(1);
+ }
+ }
+ $item->DISOWN();
+ @items = ({item => $item, label => $names[0], level => 0});
+ for (my $lev=1; $lev < scalar(@names); $lev++) {
+ $item = new yui::YTreeItem ($items[$lev-1]->{item}, $names[$lev]);
+
+ if ($selected eq $self->_getUntranslatedName($item->label(), $fullList->{list})) {
+ $item->setSelected(1) ;
+ $item->setOpen(1);
+ my $parent = $item;
+ while($parent = $parent->parent()) {
+ $parent->setOpen(1);
+ }
+ }
+ $item->DISOWN();
+ if ($lev < scalar(@names)-1) {
+ push @items, {item => $item, label => $names[$lev], level => $lev};
+ }
+ }
+ }
+ else {
+ my $prevItem = 0;
+ for (my $lev=1; $lev < scalar(@names); $lev++) {
+ my $it;
+ for ($it=1; $it < scalar(@items); $it++){
+ if ($items[$it]->{label} eq $names[$lev] && $items[$it]->{level} == $lev) {
+ $prevItem = $it;
+ last;
+ }
+ }
+ if ($it == scalar(@items)) {
+ my $item = new yui::YTreeItem ($items[$prevItem]->{item}, $names[$lev]);
+
+ if ($selected eq $self->_getUntranslatedName($item->label(), $fullList->{list})) {
+ $item->setSelected(1) ;
+ $item->setOpen(1);
+ my $parent = $item;
+ while($parent = $parent->parent()) {
+ $parent->setOpen(1);
+ }
+ }
+ $item->DISOWN();
+ push @items, {item => $item, label => $names[$lev], level => $lev};
+ }
+ }
+ }
+ }
+ $itemColl->push($items[0]->{item});
+ push @{$fullList->{items}}, $items[-1]->{item};
+
+ $treeWidget->addItems($itemColl);
+ my $align = $factory->createLeft($vbox);
+ my $hbox = $factory->createHBox($align);
+ my $aboutButton = $factory->createPushButton($hbox, N("About") );
+ $align = $factory->createRight($hbox);
+ $hbox = $factory->createHBox($align);
+ my $cancelButton = $factory->createPushButton($hbox, N("Cancel") );
+ my $okButton = $factory->createPushButton($hbox, N("Ok") );
+
+ while(1) {
+ my $event = $dialog->waitForEvent();
+ my $eventType = $event->eventType();
+
+ #event type checking
+ if ($eventType == $yui::YEvent::CancelEvent) {
+ last;
+ }
+ elsif ($eventType == $yui::YEvent::WidgetEvent) {
+ # widget selected
+ my $widget = $event->widget();
+
+ if ($widget == $cancelButton) {
+ last;
+ }
+ elsif ($widget == $aboutButton) {
+ my $license = translate($AdminPanel::Shared::License);
+ AdminPanel::Shared::AboutDialog(
+ { name => N("AdminMouse"),
+ version => $self->VERSION,
+ copyright => N("Copyright (C) %s Mageia community", '2014'),
+ license => $license,
+ comments => N("AdminMouse is the Mageia mouse management tool \n(from the original idea of Mandriva mousedrake)."),
+ website => 'http://www.mageia.org',
+ website_label => N("Mageia"),
+ authors => "Angelo Naselli <anaselli\@linux.it>\nMatteo Pasotti <matteo.pasotti\@gmail.com>",
+ translator_credits =>
+ #-PO: put here name(s) and email(s) of translator(s) (eg: "John Smith <jsmith@nowhere.com>")
+ N("_: Translator(s) name(s) & email(s)\n")}
+ );
+ }
+ elsif ($widget == $okButton) {
+ my $continue = 1;
+ my $selectedItem = $treeWidget->selectedItem();
+
+ my $it=$selectedItem;
+ my $fullname = $self->_getUntranslatedName($it->label(), $fullList->{list});
+ while($it = yui::toYTreeItem($it)->parent()) {
+ $fullname = join("|", $self->_getUntranslatedName($it->label(), $fullList->{list}), $fullname);
+ }
+
+ if ($fullname ne $prev) {
+ my $mouse_ = mouse::fullname2mouse($fullname, device => $mouse->{device});
+ if ($fullname =~ /evdev/) {
+ $mouse_->{evdev_mice} = $mouse_->{evdev_mice_all} = $mouse->{evdev_mice_all};
+ }
+ %$mouse = %$mouse_;
+ }
+
+ if ($mouse->{nbuttons} < 3 ) {
+ $mouse->{Emulate3Buttons} = AdminPanel::Shared::ask_YesOrNo('', N("Emulate third button?"));
+ }
+ if ($mouse->{type} eq 'serial') {
+ my @list = ();
+ foreach (detect_devices::serialPorts()) {
+ push @list, detect_devices::serialPort2text($_);
+ }
+ my $choice = AdminPanel::Shared::ask_fromList(N("Mouse Port"),
+ N("Please choose which serial port your mouse is connected to."),
+ \@list);
+ if ( !$choice ) {
+ $continue = 0;
+ }
+ else {
+ $mouse->{device} = $choice;
+ }
+ }
+
+ if ($continue) {
+ last;
+ }
+ }
+ }
+ }
+
+ }
+
+ # TODO manage write conf without interactive things
+ # mouse::write_conf($in->do_pkgs, $modules_conf, $mouse, 1);
+ system('systemctl', 'try-restart', 'gpm.service') if -e '/usr/lib/systemd/system/gpm.service';
+
+ $dialog->destroy();
+
+ #restore old application title
+ yui::YUI::app()->setApplicationTitle($appTitle);
+}
+
+1; \ No newline at end of file
diff --git a/AdminPanel/Shared.pm b/AdminPanel/Shared.pm
index 5d052e0..583b214 100644
--- a/AdminPanel/Shared.pm
+++ b/AdminPanel/Shared.pm
@@ -85,14 +85,17 @@ use yui;
use base qw(Exporter);
# TODO move GUI dialogs to Shared::GUI
-our @EXPORT = qw(warningMsgBox
- msgBox
- infoMsgBox
- ask_YesOrNo
- ask_OkCancel
- AboutDialog
- trim
- member);
+our @EXPORT = qw(
+ warningMsgBox
+ msgBox
+ infoMsgBox
+ ask_YesOrNo
+ ask_OkCancel
+ ask_fromList
+ AboutDialog
+ trim
+ member
+);
=head1 VERSION
@@ -284,8 +287,8 @@ sub ask_OkCancel {
=head3 DESCRIPTION
-This function create a Yes-No dialog with a 'title' and a question 'text'
-passed as parameters.
+This function create a Yes-No dialog with a 'title' and a
+question 'text' passed as parameters.
=cut
@@ -325,6 +328,96 @@ sub ask_YesOrNo {
return $retVal;
}
+
+#=============================================================
+
+=head2 ask_fromList
+
+=head3 INPUT
+
+ $title: dialog title
+ $text: combobox heading
+ $list: item list
+
+=head3 OUTPUT
+
+ undef: if Cancel button has been pressed
+ selected item: if Ok button has been pressed
+
+=head3 DESCRIPTION
+
+This function create a dialog with a combobox in which to
+choose an item from a given list.
+
+=cut
+
+#=============================================================
+
+sub ask_fromList {
+ my ($title, $text, $list) = @_;
+
+ die "Title is mandatory" if (! $title);
+ die "Heading is mandatory" if (! $text);
+ die "List is mandatory" if (! $list );
+ die "At least one element is mandatory into list" if (scalar(@$list) < 1);
+
+ my $choice = undef;
+ my $factory = yui::YUI::widgetFactory;
+
+ ## push application title
+ my $appTitle = yui::YUI::app()->applicationTitle();
+ ## set new title to get it in dialog
+ yui::YUI::app()->setApplicationTitle($title);
+
+ my $dlg = $factory->createPopupDialog($yui::YDialogNormalColor);
+ my $layout = $factory->createVBox($dlg);
+
+ my $combo = $factory->createComboBox($layout, $text, 0);
+ my $itemColl = new yui::YItemCollection;
+ foreach (@$list) {
+ my $item = new yui::YItem ($_, 0);
+ $itemColl->push($item);
+ $item->DISOWN();
+ }
+ $combo->addItems($itemColl);
+
+ my $align = $factory->createRight($layout);
+ my $hbox = $factory->createHBox($align);
+ my $okButton = $factory->createPushButton($hbox, N("Ok"));
+ my $cancelButton = $factory->createPushButton($hbox, N("Cancel"));
+
+ while (1) {
+ my $event = $dlg->waitForEvent();
+
+ my $eventType = $event->eventType();
+ #event type checking
+ if ($eventType == $yui::YEvent::CancelEvent) {
+ last;
+ }
+ elsif ($eventType == $yui::YEvent::WidgetEvent) {
+ # widget selected
+ my $widget = $event->widget();
+
+ if ($widget == $cancelButton) {
+ last;
+ }
+ elsif ($widget == $okButton) {
+ my $item = $combo->selectedItem();
+ $choice = $item->label() if ($item);
+ last;
+ }
+ }
+ }
+
+ destroy $dlg;
+
+ #restore old application title
+ yui::YUI::app()->setApplicationTitle($appTitle);
+
+ return $choice;
+}
+
+
#=============================================================
=head2 AboutDialog
diff --git a/categories.conf b/categories.conf
index a1580e1..5f06c2c 100644
--- a/categories.conf
+++ b/categories.conf
@@ -35,6 +35,9 @@
<title>Hardware</title>
<icon>/usr/share/icons/configuration_section.png</icon>
<module>
+ <class>AdminPanel::AdminMouse</class>
+ </module>
+ <module>
<title>CD/DVD Config</title>
<launcher>./modules/test</launcher>
<icon>./modules/pythonMod</icon>
diff --git a/modules/adminMouse b/modules/adminMouse
new file mode 100755
index 0000000..6af1713
--- /dev/null
+++ b/modules/adminMouse
@@ -0,0 +1,13 @@
+#!/usr/bin/perl
+
+use lib qw(/usr/lib/libDrakX);
+
+use common qw(N);
+
+use AdminPanel::AdminMouse;
+
+my $mouseMan = AdminPanel::AdminMouse->new();
+
+$mouseMan->start();
+
+1;