Minor formatting tidying up.
[qwerkisync] / Windows / ModeWindow.cpp
1 /*
2  * Copyright (C) 2011, Jamie Thompson
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public
6  * License as published by the Free Software Foundation; either
7  * version 3 of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public
15  * License along with this program; If not, see
16  * <http://www.gnu.org/licenses/>.
17  */
18
19 #include "Windows/ModeWindow.h"
20 #include "Windows/TypesWindow.h"
21 #include "Windows/ProgressWindow.h"
22
23 #include "SyncerThread.h"
24
25 #include <QtGui>
26
27 using namespace Windows;
28
29 ModeWindow::ModeWindow(Settings& settings, QWidget *parent) :
30         BaseWindow(settings, parent)
31 {
32         CreateContents();
33 }
34
35 void ModeWindow::CreateContents()
36 {
37         switch(CurrentSettings().AppMode())
38         {
39                 case Settings::APPMODE_GUI:
40                 {
41                         QVBoxLayout *layout = new QVBoxLayout();
42                         {
43                                 QLabel* lblTest = new QLabel(CurrentSettings().Directory());
44                                 layout->addWidget(lblTest);
45                                 //layout->setAlignment(lblTest, Qt::AlignHCenter | Qt::AlignTop);
46
47                                 QPushButton* btnImport = new QPushButton(QIcon(":/resources/sphone.png"), "Import");
48                                 QObject::connect(btnImport, SIGNAL(clicked()), this, SLOT(Import()));
49                                 layout->addWidget(btnImport);
50                                 layout->setAlignment(btnImport, Qt::AlignHCenter);
51
52                                 QPushButton* btnExport = new QPushButton(QIcon(":/resources/sphone.png"), "Export");
53                                 QObject::connect(btnExport, SIGNAL(clicked()), this, SLOT(Export()));
54                                 layout->addWidget(btnExport);
55                                 layout->setAlignment(btnExport, Qt::AlignHCenter);
56
57                                 layout->addWidget(new QLabel());
58
59                                 centralWidget()->setLayout(layout);
60                         }
61
62                         break;
63                 }
64
65                 case Settings::APPMODE_CONSOLE:
66                 {
67                         // Process args.
68
69                         Advance();
70                         break;
71                 }
72         }
73 }
74
75 void ModeWindow::Import()
76 {
77         CurrentSettings().setMode(Settings::MODE_IMPORT);
78         CurrentSettings().setDirectory("IMPORT");
79         Advance();
80 }
81
82 void ModeWindow::Export()
83 {
84         CurrentSettings().setMode(Settings::MODE_EXPORT);
85         CurrentSettings().setDirectory("EXPORT");
86         Advance();
87 }
88
89 void ModeWindow::Advance()
90 {
91         QWidget* next = new TypesWindow(CurrentSettings(), this);
92         next->show();
93 }
94
95 void ModeWindow::closeEvent(QCloseEvent *)
96 {
97         if(CurrentSettings().IsConfirmed())
98         {
99                 SyncerThread* tSync = new SyncerThread(CurrentSettings());
100                 QWidget* progressWindow = new ProgressWindow(CurrentSettings(), tSync);
101                 progressWindow->show();
102
103                 tSync->Sync();
104         }
105 }