aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/mpan
blob: 1b28f77c49ccac97989d4906009877c8f7877e0b (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
117
118
119
#!/usr/bin/perl
# vim: set et ts=4 sw=4:
#    Copyright 2012 Steven Tucker
#    Copyright 2013-2016 Matteo Pasotti
#    Copyright 2014-2016 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 mpanCommandLine;

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 yui;

my $cmdline = mpanCommandLine->new_with_options();

my $settings = getSettings();

if ($cmdline->devel()) {
    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();
    }
    else {
        last;
    }
}


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

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

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

=pod

=head1 main

       main launcher

=cut

1;