aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/mpan
blob: 760d771da923406c1f4c7be90e51c1ed95f78114 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/perl
# vim: set et ts=4 sw=4:
#    Copyright 2012 Steven Tucker
#    Copyright 2013 - 2015 Matteo Pasotti
#    Copyright 2014 - 2015 Angelo Naselli
#
#    This file is part of manatools
#
#    ManaTools is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 2 of the License, or
#    (at your option) any later version.
#
#    ManaTools 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 ManaTools.  If not, see <http://www.gnu.org/licenses/>.

package mpan::CommandLine;

use Moose;
extends 'ManaTools::Shared::GUI::CommandLine';

use ManaTools::Shared::Locales;

my $loc = ManaTools::Shared::Locales->new();

has 'devel' => (
    is            => 'ro',
    isa           => 'Bool',
    documentation => $loc->N('Developers mode'),
);

has 'name' => (
    is            => 'ro',
    isa           => 'Str',
    documentation => $loc->N('Application name, used for logging identifier and x application configuration directory. Default mpan'),
);

has 'title' => (
    is            => 'ro',
    isa           => 'Str',
    documentation => $loc->N('Window title. Default name value'),
);

no Moose;
__PACKAGE__->meta->make_immutable;


1;

use strict;
use warnings;
use diagnostics;
use ManaTools::Privileges;
use ManaTools::SettingsReader;
use ManaTools::MainDisplay;
use mpan::CommandLine;

use yui;

my $cmdline = mpan::CommandLine->new_with_options();

my $settings = getSettings();

if ($cmdline->devel() > 0) {
    print $loc->N("== Development mode ON ==") . "\n";
}
else {
    ask_for_authentication($settings->{priv_method}) if is_root_capability_required();
}

my $param = {};

$param->{title}     = $cmdline->title() if $cmdline->title();
$param->{name}      = $cmdline->name() if $cmdline->name();
$param->{configDir} = $cmdline->conf_dir() if $cmdline->conf_dir();


my $mainWin = new ManaTools::MainDisplay($param);
while (1) {
    my $launch = $mainWin->start();
    $mainWin->cleanup();

    if ($launch) {
        $launch->start();
    }
}


# mpan settings
sub getSettings {
    my ($self) = @_;

    # yui commandline parser
    my $confDir = $cmdline->conf_dir() || "/etc";
    chop $confDir if substr($confDir, -1) eq '/';
    $confDir .= '/mpan';

    # configuration file name
    my $fileName = "$confDir/settings.conf";
    return new ManaTools::SettingsReader({fileName => $fileName});
}

=pod

=head1 main

       main launcher

=cut

1;