importwizarddlg.cpp 8.88 KB
Newer Older
Benjamin Girault's avatar
Benjamin Girault committed
1
2
3
/* ============================================================
 * 
 * This file is a part of kipi-plugins project
4
 * http://www.digikam.org
Benjamin Girault's avatar
Benjamin Girault committed
5
6
7
8
9
 *
 * Date        : 2011-05-23
 * Description : a plugin to create panorama by fusion of several images.
 * Acknowledge : based on the expoblending plugin
 *
Benjamin Girault's avatar
Benjamin Girault committed
10
 * Copyright (C) 2011-2012 by Benjamin Girault <benjamin dot girault at gmail dot com>
Gilles Caulier's avatar
polish    
Gilles Caulier committed
11
 * Copyright (C) 2009-2012 by Gilles Caulier <caulier dot gilles at gmail dot com>
Benjamin Girault's avatar
Benjamin Girault committed
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
 *
 * This program 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, or (at your option) any later version.
 *
 * 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.
 *
 * ============================================================ */

#include "importwizarddlg.moc"

27
28
29
30
31
// Qt includes

#include <QDesktopWidget>
#include <QApplication>

Benjamin Girault's avatar
Benjamin Girault committed
32
33
34
35
36
37
38
// KDE includes

#include <kmenu.h>
#include <klocale.h>
#include <khelpmenu.h>
#include <kpushbutton.h>
#include <ktoolinvocation.h>
39
#include <kmessagebox.h>
Benjamin Girault's avatar
Benjamin Girault committed
40
41
42
43
44
45
46
47
48
49

// LibKIPI includes

#include <libkipi/interface.h>

// Locale incudes.

#include "manager.h"
#include "actionthread.h"
#include "aboutdata.h"
50
#include "cpfindbinary.h"
Benjamin Girault's avatar
Benjamin Girault committed
51

Benjamin Girault's avatar
Benjamin Girault committed
52
53
54
55
#include "intropage.h"
#include "itemspage.h"
#include "preprocessingpage.h"
#include "optimizepage.h"
Benjamin Girault's avatar
Benjamin Girault committed
56
#include "previewpage.h"
57
#include "lastpage.h"
Benjamin Girault's avatar
Benjamin Girault committed
58
59
60
61

namespace KIPIPanoramaPlugin
{

62
63
64
65
66
67
68
69
struct ImportWizardDlg::ImportWizardDlgPriv
{
    ImportWizardDlgPriv()
      : mngr(0),
        introPage(0),
        itemsPage(0),
        preProcessingPage(0),
        optimizePage(0),
Benjamin Girault's avatar
Benjamin Girault committed
70
        previewPage(0),
71
        lastPage(0)
Benjamin Girault's avatar
Benjamin Girault committed
72
    {
73
    }
Benjamin Girault's avatar
Benjamin Girault committed
74

Gilles Caulier's avatar
polish    
Gilles Caulier committed
75
    Manager*           mngr;
Benjamin Girault's avatar
Benjamin Girault committed
76

Gilles Caulier's avatar
polish    
Gilles Caulier committed
77
78
79
80
81
82
    IntroPage*         introPage;
    ItemsPage*         itemsPage;
    PreProcessingPage* preProcessingPage;
    OptimizePage*      optimizePage;
    PreviewPage*       previewPage;
    LastPage*          lastPage;
83
};
Benjamin Girault's avatar
Benjamin Girault committed
84

Gilles Caulier's avatar
polish    
Gilles Caulier committed
85
ImportWizardDlg::ImportWizardDlg(Manager* const mngr, QWidget* const parent)
Benjamin Girault's avatar
Benjamin Girault committed
86
    : KAssistantDialog(parent), d(new ImportWizardDlgPriv)
87
88
89
{
    setModal(false);
    setWindowTitle(i18n("Panorama Creator Wizard"));
Benjamin Girault's avatar
Benjamin Girault committed
90

91
    d->mngr              = mngr;
Benjamin Girault's avatar
Benjamin Girault committed
92
    d->introPage         = new IntroPage(d->mngr, this);
93
94
95
    d->itemsPage         = new ItemsPage(d->mngr, this);
    d->preProcessingPage = new PreProcessingPage(d->mngr, this);
    d->optimizePage      = new OptimizePage(d->mngr, this);
Benjamin Girault's avatar
Benjamin Girault committed
96
    d->previewPage       = new PreviewPage(d->mngr, this);
97
98
99
100
101
102
    d->lastPage          = new LastPage(d->mngr, this);

    // ---------------------------------------------------------------
    // About data and help button.

    disconnect(this, SIGNAL(helpClicked()),
Benjamin Girault's avatar
Benjamin Girault committed
103
104
                this, SLOT(slotHelp()));

105
106
107
108
109
110
111
    KHelpMenu* helpMenu = new KHelpMenu(this, d->mngr->about(), false);
    helpMenu->menu()->removeAction(helpMenu->menu()->actions().first());
    QAction* handbook   = new QAction(i18n("Handbook"), this);
    connect(handbook, SIGNAL(triggered(bool)),
            this, SLOT(slotHelp()));
    helpMenu->menu()->insertAction(helpMenu->menu()->actions().first(), handbook);
    button(Help)->setMenu(helpMenu->menu());
Benjamin Girault's avatar
Benjamin Girault committed
112

113
    // ---------------------------------------------------------------
Benjamin Girault's avatar
Benjamin Girault committed
114

115
116
117
118
119
    QDesktopWidget* desktop = QApplication::desktop();
    int screen = desktop->screenNumber();
    QRect srect = desktop->availableGeometry(screen);
    resize(800 <= srect.width()  ? 800 : srect.width(),
           750 <= srect.height() ? 750 : srect.height());
120
121
122

    connect(d->introPage, SIGNAL(signalIntroPageIsValid(bool)),
            this, SLOT(slotIntroPageIsValid(bool)));
Benjamin Girault's avatar
Benjamin Girault committed
123

124
125
    connect(d->itemsPage, SIGNAL(signalItemsPageIsValid(bool)),
            this, SLOT(slotItemsPageIsValid(bool)));
126

127
128
    connect(d->preProcessingPage, SIGNAL(signalPreProcessed(bool)),
            this, SLOT(slotPreProcessed(bool)));
Benjamin Girault's avatar
Benjamin Girault committed
129

130
131
    connect(d->optimizePage, SIGNAL(signalOptimized(bool)),
            this, SLOT(slotOptimized(bool)));
Benjamin Girault's avatar
Benjamin Girault committed
132

133
134
135
    connect(d->previewPage, SIGNAL(signalPreviewStitchingFinished(bool)),
            this, SLOT(slotPreviewStitchingFinished(bool)));

136
137
    connect(d->previewPage, SIGNAL(signalStitchingFinished(bool)),
            this, SLOT(slotStitchingFinished(bool)));
Benjamin Girault's avatar
Benjamin Girault committed
138

139
140
    connect(d->lastPage, SIGNAL(signalCopyFinished(bool)),
            this, SLOT(slotCopyFinished(bool)));
141

142
143
144
    connect(d->lastPage, SIGNAL(signalIsValid(bool)),
            this, SLOT(slotLastPageIsValid(bool)));

145
    setValid(d->introPage->page(), d->introPage->binariesFound());
146
}
Benjamin Girault's avatar
Benjamin Girault committed
147

148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
ImportWizardDlg::~ImportWizardDlg()
{
    delete d;
}

Manager* ImportWizardDlg::manager() const
{
    return d->mngr;
}

KUrl::List ImportWizardDlg::itemUrls() const
{
    return d->itemsPage->itemUrls();
}

void ImportWizardDlg::next()
{
    if (currentPage() == d->itemsPage->page())
Benjamin Girault's avatar
Benjamin Girault committed
166
    {
167
        d->mngr->setItemsList(d->itemsPage->itemUrls());
Benjamin Girault's avatar
Benjamin Girault committed
168
    }
169
    else if (currentPage() == d->preProcessingPage->page())
Benjamin Girault's avatar
Benjamin Girault committed
170
    {
Benjamin Girault's avatar
Benjamin Girault committed
171
        // Do not give access to Next button during pre-processing.
172
173
174
175
        setValid(d->preProcessingPage->page(), false);
        d->preProcessingPage->process();
        // Next is handled with signals/slots
        return;
Benjamin Girault's avatar
Benjamin Girault committed
176
    }
177
    else if (currentPage() == d->optimizePage->page())
Benjamin Girault's avatar
Benjamin Girault committed
178
    {
Benjamin Girault's avatar
Benjamin Girault committed
179
        // Do not give access to Next button during optimization.
180
181
182
183
        setValid(d->optimizePage->page(), false);
        d->optimizePage->process();
        // Next is handled with signals/slots
        return;
Benjamin Girault's avatar
Benjamin Girault committed
184
    }
Benjamin Girault's avatar
Benjamin Girault committed
185
186
    else if (currentPage() == d->previewPage->page())
    {
187
        // And start the final stitching process
Benjamin Girault's avatar
Benjamin Girault committed
188
189
        setValid(d->previewPage->page(), false);
        d->previewPage->startStitching();
190
191

        // Next will be handled using signals/slots
Benjamin Girault's avatar
Benjamin Girault committed
192
193
        return;
    }
Benjamin Girault's avatar
Benjamin Girault committed
194
195
    else if (currentPage() == d->lastPage->page())
    {
196
197
        setValid(d->lastPage->page(), false);
        d->lastPage->copyFiles();
Benjamin Girault's avatar
Benjamin Girault committed
198
199
        return;
    }
Benjamin Girault's avatar
Benjamin Girault committed
200

201
202
    KAssistantDialog::next();
}
Benjamin Girault's avatar
Benjamin Girault committed
203

204
205
206
207
void ImportWizardDlg::back()
{
    if (currentPage() == d->preProcessingPage->page())
    {
208
209
210
211
212
        if (!d->preProcessingPage->cancel())
        {
            setValid(d->preProcessingPage->page(), true);
            return;
        }
213
        setValid(d->preProcessingPage->page(), true);
Benjamin Girault's avatar
Benjamin Girault committed
214
    }
215
    else if (currentPage() == d->optimizePage->page())
Benjamin Girault's avatar
Benjamin Girault committed
216
    {
217
218
219
220
221
        if (!d->optimizePage->cancel())
        {
            setValid(d->optimizePage->page(), true);
            return;
        }
222
        setValid(d->optimizePage->page(), true);
Benjamin Girault's avatar
Benjamin Girault committed
223
224
225
226
        d->preProcessingPage->resetPage();
    }
    else if (currentPage() == d->previewPage->page())
    {
227
228
229
230
231
232
233
234
235
236
237
        if (d->previewPage->cancel())
        {
            setValid(d->previewPage->page(), true);

            d->optimizePage->resetPage();
        }
        else
        {
            setValid(d->previewPage->page(), true);
            return;
        }
Benjamin Girault's avatar
Benjamin Girault committed
238
239
240
    }
    else if (currentPage() == d->lastPage->page())
    {
Benjamin Girault's avatar
Benjamin Girault committed
241
        KAssistantDialog::back();
Benjamin Girault's avatar
Benjamin Girault committed
242
        d->previewPage->resetPage();
Benjamin Girault's avatar
Benjamin Girault committed
243
        return;
Benjamin Girault's avatar
Benjamin Girault committed
244
245
    }

246
247
248
    KAssistantDialog::back();
}

Benjamin Girault's avatar
Benjamin Girault committed
249
250
251
252
253
254
void ImportWizardDlg::accept()
{
    setValid(d->lastPage->page(), false);
    d->lastPage->copyFiles();
}

255
256
257
258
259
void ImportWizardDlg::slotIntroPageIsValid(bool binariesFound)
{
    setValid(d->introPage->page(), binariesFound);
}

Benjamin Girault's avatar
Benjamin Girault committed
260
261
262
263
264
void ImportWizardDlg::slotItemsPageIsValid(bool valid)
{
    setValid(d->itemsPage->page(), valid);
}

265
void ImportWizardDlg::slotPreProcessed(bool success)
266
{
267
    if (!success)
Benjamin Girault's avatar
Benjamin Girault committed
268
    {
269
270
        // pre-processing failed.
        setValid(d->preProcessingPage->page(), false);
Benjamin Girault's avatar
Benjamin Girault committed
271
    }
272
    else
273
    {
274
        // pre-processing Done.
Benjamin Girault's avatar
Benjamin Girault committed
275
        setValid(d->preProcessingPage->page(), true);
276
        d->optimizePage->resetPage();
277
        KAssistantDialog::next();
278
    }
279
}
280

281
void ImportWizardDlg::slotOptimized(bool success)
282
{
283
    if (!success)
Benjamin Girault's avatar
Benjamin Girault committed
284
    {
285
286
        // Optimization failed.
        setValid(d->optimizePage->page(), false);
Benjamin Girault's avatar
Benjamin Girault committed
287
    }
288
289
290
    else
    {
        // Optimization finished.
Benjamin Girault's avatar
Benjamin Girault committed
291
        setValid(d->optimizePage->page(), true);
292
        setValid(d->previewPage->page(), true);
293
        KAssistantDialog::next();
Benjamin Girault's avatar
Benjamin Girault committed
294
295
296

        // Start the Preview generation
        d->previewPage->computePreview();
297
298
299
    }
}

300
301
302
303
304
305
306
307
void ImportWizardDlg::slotPreviewStitchingFinished(bool success)
{
    if (!success)
    {
        setValid(d->previewPage->page(), false);
    }
}

308
void ImportWizardDlg::slotStitchingFinished(bool success)
Benjamin Girault's avatar
Benjamin Girault committed
309
{
310
    if (success)
Benjamin Girault's avatar
Benjamin Girault committed
311
    {
312
313
314
        setValid(d->previewPage->page(), true);
        KAssistantDialog::next();
        d->lastPage->resetTitle();
Benjamin Girault's avatar
Benjamin Girault committed
315
316
317
    }
}

318
void ImportWizardDlg::slotCopyFinished(bool success)
Benjamin Girault's avatar
Benjamin Girault committed
319
{
320
    if (success)
321
322
323
324
325
326
327
    {
        QDialog::accept();
    }
    else
    {
        setValid(d->lastPage->page(), true);
    }
Benjamin Girault's avatar
Benjamin Girault committed
328
329
}

330
331
332
333
334
void ImportWizardDlg::slotLastPageIsValid(bool isValid)
{
    setValid(d->lastPage->page(), isValid);
}

Benjamin Girault's avatar
Benjamin Girault committed
335
void ImportWizardDlg::slotHelp()
336
{
Benjamin Girault's avatar
Benjamin Girault committed
337
    KToolInvocation::invokeHelp("panorama", "kipi-plugins");
338
}
Benjamin Girault's avatar
Benjamin Girault committed
339
340

} // namespace KIPIPanoramaPlugin