summaryrefslogtreecommitdiffstats
path: root/kipi-plugins/cdarchiving/plugin_cdarchiving.cpp
blob: b459814ee4138e7298d192aa44e3712a11cdb93a (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
//////////////////////////////////////////////////////////////////////////////
//
//    PLUGIN_CDARCHIVING.CPP
//
//    Copyright (C) 2003-2004 Gilles Caulier <caulier dot gilles at gmail dot com>
//
//    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 of the License, 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.
//
//    You should have received a copy of the GNU General Public License
//    along with this program; if not, write to the Free Software
//    Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA.
//
//////////////////////////////////////////////////////////////////////////////

// KDE includes

#include <tdeaction.h>
#include <kapplication.h>
#include <tdeconfig.h>
#include <kdebug.h>
#include <tdeversion.h>
#include <kgenericfactory.h>
#include <kinstance.h>
#include <klibloader.h>
#include <klocale.h>

// LibKipi includes

#include <libkipi/batchprogressdialog.h>

// Local includes

#include "actions.h"
#include "cdarchiving.h"
#include "plugin_cdarchiving.h"

typedef KGenericFactory<Plugin_CDArchiving> Factory;

K_EXPORT_COMPONENT_FACTORY( kipiplugin_cdarchiving,
                            Factory("kipiplugin_cdarchiving"))

// -----------------------------------------------------------
Plugin_CDArchiving::Plugin_CDArchiving(TQObject *parent, const char*, const TQStringList&)
        : KIPI::Plugin( Factory::instance(), parent, "CDArchiving")
{
    kdDebug( 51001 ) << "Plugin_CDArchiving plugin loaded" << endl;
}

void Plugin_CDArchiving::setup( TQWidget* widget )
{
    KIPI::Plugin::setup( widget );

    m_action_cdarchiving = new TDEAction (i18n("Archive to CD/DVD..."),     // Menu message.
                                        "cd",                             // Menu icon.
                                        0,
                                        this,
                                        TQT_SLOT(slotActivate()),
                                        actionCollection(),
                                        "cd_archiving");

    addAction( m_action_cdarchiving );
    m_cdarchiving = 0;
}


/////////////////////////////////////////////////////////////////////////////////////////////////////

Plugin_CDArchiving::~Plugin_CDArchiving()
{
    // No need to delete m_cdarchiving as its a TQObject child of this
    // and will be deleted automatically
}


/////////////////////////////////////////////////////////////////////////////////////////////////////

void Plugin_CDArchiving::slotActivate()
{
    m_progressDlg = 0;

    KIPI::Interface* interface = dynamic_cast< KIPI::Interface* >( parent() );

    if ( !interface )
    {
        kdError( 51000 ) << "Kipi interface is null!" << endl;
        return;
    }

    m_cdarchiving = new KIPICDArchivingPlugin::CDArchiving(
        interface,
        this, m_action_cdarchiving);

    if ( m_cdarchiving->showDialog() )
    {
        m_cdarchiving->prepare();
        m_cdarchiving->run();
    }
}


/////////////////////////////////////////////////////////////////////////////////////////////////////

void Plugin_CDArchiving::slotCancel()
{
    m_cdarchiving->stop();
    m_cdarchiving->removeTmpFiles();
}


/////////////////////////////////////////////////////////////////////////////////////////////////////

void Plugin_CDArchiving::customEvent(TQCustomEvent *event)
{
    if (!event) return;

    if (!m_progressDlg)
    {
        m_progressDlg = new KIPI::BatchProgressDialog(TQT_TQWIDGET(kapp->activeWindow()), i18n("Archive to CD/DVD"));

        connect(m_progressDlg, TQT_SIGNAL(cancelClicked()),
                this, TQT_SLOT(slotCancel()));

        m_current = 0;
        m_progressDlg->show();
    }

    KIPICDArchivingPlugin::EventData *d = (KIPICDArchivingPlugin::EventData*) event->data();

    if (!d) return;

    if (d->starting)
    {
        TQString text;

        switch (d->action)
        {
        case(KIPICDArchivingPlugin::Initialize):
        {
            text = i18n("Initialising...");
            m_total = d->total;
            break;
        }

        case(KIPICDArchivingPlugin::BuildHTMLiface):
        {
            text = i18n("Making main HTML interface...");
            break;
        }

        case(KIPICDArchivingPlugin::BuildAlbumHTMLPage):
        {
            text = i18n("Making HTML pages for Album '%1'...").arg(d->albumName);
            break;
        }

        case(KIPICDArchivingPlugin::BuildAutoRuniface):
        {
            text = i18n("Making AutoRun interface...");
            break;
        }

        case(KIPICDArchivingPlugin::ResizeImages):
        {
            text = i18n("Creating thumbnail for '%1'...").arg(d->fileName);
            break;
        }

        case(KIPICDArchivingPlugin::BuildK3bProject):
        {
            text = i18n("Making K3b project...");
            break;
        }

        case(KIPICDArchivingPlugin::Progress):
        {
            text = d->message;
            break;
        }

        default:
        {
            kdWarning( 51000 ) << "Plugin_CDArchiving: Unknown 'Starting' event: " << d->action << endl;
        }
        }

        m_progressDlg->addedAction(text, KIPI::StartingMessage);
    }
    else
    {
        TQString text;

        if (d->success)
        {
            switch (d->action)
            {
            case(KIPICDArchivingPlugin::BuildHTMLiface):
            {
                ++m_current;
                text = i18n("Main HTML interface creation completed.");
                break;
            }

            case(KIPICDArchivingPlugin::BuildAlbumHTMLPage):
            {
                ++m_current;
                text = i18n("HTML page creation for Album '%1' completed.").arg(d->albumName);
                break;
            }

            case(KIPICDArchivingPlugin::ResizeImages):
            {
                ++m_current;
                text = i18n("Creating thumbnail for '%1' done.").arg(d->fileName);
                break;
            }

            case(KIPICDArchivingPlugin::BuildAutoRuniface):
            {
                ++m_current;
                text = i18n("AutoRun interface creation completed.");
                break;
            }

            case(KIPICDArchivingPlugin::BuildK3bProject):
            {
                ++m_current;
                text = i18n("K3b project creation completed.");
                break;
            }

            default:
            {
                kdWarning( 51000 ) << "Plugin_CDArchiving: Unknown 'Success' event: " << d->action << endl;
            }
            }

            m_progressDlg->addedAction(text, KIPI::SuccessMessage);
        }
        else
        {
            switch (d->action)
            {
            case(KIPICDArchivingPlugin::ResizeImages):
            {
                text = i18n("Failed to create thumbnail for '%1'").arg(d->fileName);
                m_progressDlg->addedAction(text, KIPI::WarningMessage);
                m_progressDlg->setProgress(m_current, m_total);
                break;
            }

            case(KIPICDArchivingPlugin::BuildHTMLiface):
            {
                ++m_current;
                text = i18n("Failed to create HTML interface: %1")
                       .arg(d->message);
                m_progressDlg->addedAction(text, KIPI::ErrorMessage);
                m_progressDlg->setProgress(m_current, m_total);
                slotCancel();
                return;
                break;
            }

            case(KIPICDArchivingPlugin::BuildAlbumHTMLPage):
            {
                text = i18n("Failed to create HTML pages for Album '%1'")
                       .arg(d->albumName);
                m_progressDlg->addedAction(text, KIPI::ErrorMessage);
                m_progressDlg->setProgress(m_current, m_total);
                slotCancel();
                return;
                break;
            }

            case(KIPICDArchivingPlugin::BuildK3bProject):
            {
                ++m_current;
                text = i18n("Failed to create K3b project.");
                m_progressDlg->addedAction(text, KIPI::ErrorMessage);
                m_progressDlg->setProgress(m_current, m_total);
                slotCancel();
                return;
                break;
            }

            case(KIPICDArchivingPlugin::Error):
            {
                text = d->message;
                m_progressDlg->addedAction(text, KIPI::ErrorMessage);
                m_progressDlg->setProgress(m_current, m_total);
                slotCancel();
                return;
                break;
            }

            default:
            {
                kdWarning( 51000 ) << "Plugin_CDArchiving: Unknown 'Failed' event: " << d->action << endl;
            }
            }
        }

        m_progressDlg->setProgress(m_current, m_total);

        if ( d->action == KIPICDArchivingPlugin::BuildK3bProject )
        {
            m_current = 0;

#if TDE_VERSION >= 0x30200
            m_progressDlg->setButtonCancel( KStdGuiItem::close() );
#else
            m_progressDlg->setButtonCancelText( i18n("&Close") );
#endif

            disconnect(m_progressDlg, TQT_SIGNAL(cancelClicked()),
                       this, TQT_SLOT(slotCancel()));

            // Invoke K3b program.

            m_progressDlg->addedAction(i18n("Starting K3b program..."),
                                       KIPI::StartingMessage);
            m_cdarchiving->invokeK3b();
        }
    }

    kapp->processEvents();
    delete d;
}


/////////////////////////////////////////////////////////////////////////////////////////////////////

KIPI::Category Plugin_CDArchiving::category( TDEAction* action ) const
{
    if ( action == m_action_cdarchiving )
        return KIPI::EXPORTPLUGIN;

    kdWarning( 51000 ) << "Unrecognized action for plugin category identification" << endl;
    return KIPI::EXPORTPLUGIN; // no warning from compiler, please
}


#include "plugin_cdarchiving.moc"