summaryrefslogtreecommitdiffstats
path: root/abs/core/mythinstall/MythVantage-app/mythinstall/installationtype.cpp
blob: 93d45aed0fb33df7809c4c80ffd667f22a881e0a (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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
//#include <QObject>
#include <mythcontext.h>
#include <unistd.h>
#include <QTextStream>
#include <qdir.h>

#include "mv_common.h"
#include "mythprogressdialog.h"
#include "installationtype.h"
#include "mythsystemlegacy.h"

int mythinstalltype (QString  tmp_install_drive)
{
    QString line;
    QString disksize;
    QString rootsize;
    QString homesize;
    QString sqlsize;
    QString useswap;
    QString swapsize;
    QString datasize;
    QString usealldata;
    int neededsize;
    int disksizeMB;

    int retc = 1;
    while ( retc != 0 )
    {
        Mythinstalltype setting;
        //FINDME  this is needed to populate the default values and have the triggered config work
        setting.Load();
        setting.Save();

        MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack();
        StandardSettingDialog *ssd =
            new StandardSettingDialog(mainStack, "mythinstalltypesettings",
                                      new Mythinstalltype());

        if (ssd->Create())
            mainStack->AddScreen(ssd);
        else
            delete ssd;

        //if ( setting.exec() == QDialog::Accepted )
        //{
            //get users sizes
            rootsize = gCoreContext->GetSetting("HOSTOSsize");
            homesize = gCoreContext->GetSetting("HOSTHOMEsize");
            sqlsize = gCoreContext->GetSetting("HOSTDatabasesize");
            useswap = gCoreContext->GetSetting("HostUseSWAP");
            swapsize = gCoreContext->GetSetting("HOSTSWAPsize");
            usealldata = gCoreContext->GetSetting("HostUseALLdata");
            datasize = gCoreContext->GetSetting("HOSTDATAsize");
            //check if using swap
            if ( useswap == "0" )
                swapsize = "0";
            //calculate size of all partitions;
            neededsize = rootsize.toInt() * 1024 + homesize.toInt() *1024 +
                         sqlsize.toInt() * 1024 + swapsize.toInt();
            //add 300 MB to neededsize if usealldata is enabled
            if ( usealldata == "1" )
                neededsize = neededsize + 300;
            else
                neededsize = neededsize + datasize.toInt() * 1024;
            //get selected drive size
            //using myth_system as QFile wouldn't read /proc/partitions directly
            myth_system("cat /proc/partitions > /tmp/proc.partitions");
            QFile file("/tmp/proc.partitions");
            if (file.open(QIODevice::ReadOnly | QIODevice::Text))
            {
                QTextStream t( &file );
                while (!t.atEnd())
                {
                    line = t.readLine();
                    line = line.simplified();
                    if ( line.endsWith(tmp_install_drive) )
                    {
                        disksize = line.section( " ", 2, 2 );
                        //QTextStream(stdout) << "disksize:" + disksize << endl;
                        break;
                    }
                }
            }
            file.close();
            //convert to MB and match calulation in installdialog.cpp
            disksizeMB = qRound(disksize.toFloat() * 1024 / 1000000);
/* FIXME change to mythui
            if (neededsize > disksizeMB)
            {
                DialogCode val = MythPopupBox::Show2ButtonPopup(
                                       GetMythMainWindow(),
                                       "Error", "The total partition sizes (" + QString::number(neededsize) + " MB) are too large for the selected drive (" + QString::number(disksizeMB) + " MB). Continuing may result in a failed install.",
                                       QObject::tr("Continue"),
                                       QObject::tr("Try Again"),
                                       kDialogCodeButton1);
                if ( val == kDialogCodeButton0 )
                {
                    retc = 0;
                }
                else
                {
                    retc = 1;
                }
            }
            else
            {
                retc = 0;
            }
*/
    }
    return retc;
};

static HostComboBoxSetting *HOSTinstallationtype()
{
    HostComboBoxSetting *gc = new HostComboBoxSetting("HOSTinstallationtype");
    gc->setLabel(QObject::tr("Installation Type"));
    gc->addSelection("Full/Auto") ;
    gc->addSelection("Upgrade");
    //gc->setValue("Full/Auto");
    gc->setHelpText(QObject::tr("Full install will erase the entire drive and repartition. Upgrade will format only the first parition of the drive. Only LinHES R8.0 or newer can use Upgrade."));
    return gc;
}

static HostSpinBoxSetting *HOSTOSsize()
{
#ifdef __MVAPP__
    HostSpinBoxSetting *gc = new HostSpinBoxSetting("HOSTOSsize", 2, 15, 1, true);
#else
    HostSpinBoxSetting *gc = new HostSpinBoxSetting("HOSTOSsize", 3, 25, 1, true);
#endif
    gc->setLabel(QObject::tr("OS Size (GB)"));
    gc->setValue(2);
    gc->setHelpText(QObject::tr("Amount of space allocated for the root OS partition."));
    return gc;
}

static HostSpinBoxSetting *HOSTDATAsize()
{
    HostSpinBoxSetting *gc = new HostSpinBoxSetting("HOSTDATAsize", 2, 1500, 1, true);
    gc->setLabel(QObject::tr("Data Size (GB)"));
    gc->setValue(3);
    gc->setHelpText(QObject::tr("Amount of space allocated for the data partiton."));
    return gc;
}

static HostSpinBoxSetting *HOSTHOMEsize()
{
    HostSpinBoxSetting *gc = new HostSpinBoxSetting("HOSTHOMEsize", 1, 1500, 1, true);
    gc->setLabel(QObject::tr("Home Size (GB)"));
    gc->setValue(3);
    gc->setHelpText(QObject::tr("Amount of space allocated for the home directories partition. Three to five GB will be sufficient for most people. The home partition will be the same filesystem as the root OS."  ));
    return gc;
}


static HostSpinBoxSetting *HOSTDatabasesize()
{
    HostSpinBoxSetting *gc = new HostSpinBoxSetting("HOSTDatabasesize", 1, 20, 1, true);
    gc->setLabel(QObject::tr("Database Size (GB)"));
    gc->setValue(4);
    gc->setHelpText(QObject::tr("Amount of space allocated for the database partition. Two GB is more then enough for most people. The database partition space will be formatted with the ext3 filesystem."));
    return gc;
}


static HostSpinBoxSetting *HOSTSWAPsize()
{
    QString currentitem;
    QString line;
    QFile file("/proc/meminfo");
    if ( file.open(QIODevice::ReadOnly | QIODevice::Text) )
    {
        QTextStream t( &file );        // use a text stream
        line = t.readLine();
        if ( line.startsWith("MemTotal:") )
        {
            currentitem = line.simplified();
            currentitem = currentitem.section( " ", 1, 1 );
        }
    }
    file.close();
    bool ok;
    int mem = currentitem.toInt( &ok, 10 );     // dec == 0, ok == FALSE
    //QTextStream(stdout) << mem << endl;
    mem = mem / 1024 + 16;
    //QTextStream(stdout) << mem << endl;

    if ( !  ok )
        mem = 257 ;
    //QTextStream(stdout) << mem << endl;
    HostSpinBoxSetting *gc = new HostSpinBoxSetting("HOSTSWAPsize", 256, 256000, 256, true);
    gc->setLabel(QObject::tr("Swap Size (MB)"));
    gc->setValue(mem);
    gc->setHelpText(QObject::tr("Amount of space allocated for the swap partition."  ));
    return gc;
}

static HostCheckBoxSetting *HostUseSWAP()
{
    HostCheckBoxSetting *gc = new HostCheckBoxSetting("HostUseSWAP");
    gc->setLabel(QObject::tr("Use Swap"));
    gc->setValue(true);
    gc->setHelpText(QObject::tr("Enable or disable the swap partition."));
    return gc;
};

static HostCheckBoxSetting *HostUseALLdata()
{
    HostCheckBoxSetting *gc = new HostCheckBoxSetting("HostUseALLdata");
    gc->setLabel(QObject::tr("Use all remaining space for data"));
    gc->setValue(true);
    gc->setHelpText(QObject::tr("If checked the remaining space on the drive will be used for storage. Otherwise you can set the size of the partition."));
    return gc;
};


static HostComboBoxSetting *HOSTdatafstype()
{
    HostComboBoxSetting *gc = new HostComboBoxSetting("HOSTdatafstype");
    gc->setLabel(QObject::tr("Data File System"));
    gc->addSelection("ext3") ;
    gc->addSelection("ext4") ;
   // gc->addSelection("reiserfs");
    gc->addSelection("jfs");
    gc->addSelection("xfs");
    //gc->addSelection("btrfs");
    gc->setHelpText(QObject::tr("File system type for data storage."));
    return gc;
}

static HostComboBoxSetting *HOSTuprootfstype()
{
    HostComboBoxSetting *gc = new HostComboBoxSetting("HOSTuprootfstype");
    gc->setLabel(QObject::tr("OS File System"));
    gc->addSelection("ext3") ;
    gc->addSelection("ext4") ;
    gc->addSelection("reiserfs");
    gc->addSelection("jfs");
    //gc->addSelection("xfs");
    //gc->addSelection("btrfs");
    gc->addSelection("Do_not_format");
    gc->setHelpText(QObject::tr("File system type for OS. "));
    return gc;
}

static HostComboBoxSetting *HOSTrootfstype()
{
    HostComboBoxSetting *gc = new HostComboBoxSetting("HOSTrootfstype");
    gc->setLabel(QObject::tr("Root File System"));
    gc->addSelection("ext3") ;
    gc->addSelection("ext4") ;
    gc->addSelection("reiserfs");
    gc->addSelection("jfs");
    //gc->addSelection("btrfs");
    //gc->addSelection("xfs");
    gc->setHelpText(QObject::tr("File system type for root OS."));
    return gc;
}

class USESwap : public GroupSetting
{
  public:
    USESwap()
    {
//        TriggeredConfigurationGroup(true,false,true,true,false,false,false,true) {
//        SetVertical(false);
        HostCheckBoxSetting* useswap = HostUseSWAP();
        addChild(useswap);
//        setTrigger(useswap);

//        ConfigurationGroup* swapyes = new VerticalConfigurationGroup(false);
//        swapyes->addChild(HOSTSWAPsize());
//        addTarget("1", swapyes );
//        addTarget("0",  new VerticalConfigurationGroup(true));
        useswap->addTargetedChild("1", HOSTSWAPsize());
    }
};

class DATAsize : public GroupSetting
{
  public:
    DATAsize()
    {
//        TriggeredConfigurationGroup(true,false,true,true,false,false,false,true) {
//        SetVertical(false);
//        Setting* datasize = HostUseALLdata();
        HostCheckBoxSetting* datasize = HostUseALLdata();
        addChild(datasize);
//        setTrigger(datasize);

//        ConfigurationGroup* alldatano = new VerticalConfigurationGroup(false);
//        alldatano->addChild(HOSTDATAsize());
//        alldatano->addChild(HOSTdatafstype());
        datasize->addTargetedChild("1", HOSTDATAsize());
        datasize->addTargetedChild("1", HOSTdatafstype());
        datasize->addTargetedChild("0", HOSTdatafstype());

//        ConfigurationGroup* alldatayes = new VerticalConfigurationGroup(false);
//        alldatayes->addChild(HOSTdatafstype());

//        addTarget("1", alldatayes);
//        addTarget("0", alldatano);
    }
};



class Installationtype : public GroupSetting
{
  public:
    Installationtype()
    {
//        TriggeredConfigurationGroup(true,false,true,true,false,false,false,true) {
        setLabel(QObject::tr("LinHES Install"));
//        Setting *Mtemplate = HOSTinstallationtype();
        HostComboBoxSetting *Mtemplate = HOSTinstallationtype();
        addChild(Mtemplate);
//        setTrigger(Mtemplate);

//        ConfigurationGroup *ospartition = new GridConfigurationGroup(2,false);
//            ospartition->addChild(HOSTOSsize());
//            ospartition->addChild(HOSTrootfstype());
//            ospartition->addChild(HOSTHOMEsize());
//            ospartition->addChild(HOSTDatabasesize());
        Mtemplate->addTargetedChild("1", HOSTOSsize());
        Mtemplate->addTargetedChild("1", HOSTrootfstype());
        Mtemplate->addTargetedChild("1", HOSTHOMEsize());
        Mtemplate->addTargetedChild("1", HOSTDatabasesize());
        Mtemplate->addTargetedChild("0", HOSTuprootfstype());


//        ConfigurationGroup *tupgrade = new VerticalConfigurationGroup(false);
//        tupgrade->addChild(HOSTuprootfstype());

//        ConfigurationGroup *tfull = new VerticalConfigurationGroup(false);
//         tfull->addChild(HOSTOSsize());
//         tfull->addChild(HOSTrootfstype());
//        tfull->addChild(ospartition);
//        tfull->addChild(new USESwap);
//        tfull->addChild(new DATAsize);

//        addTarget("Upgrade",tupgrade );
//        addTarget("Full/Auto", tfull);
    }
};

Mythinstalltype::Mythinstalltype()
{
    //Reseting the install type to remove "NET"
    if ( gCoreContext->GetSetting("Hostinstallationtype")  == "NET")
        gCoreContext->SaveSetting("HOSTinstallationtype","Full/Auto");
    Installationtype *installationtype = new Installationtype();
    addChild(installationtype);
};