piwigowindow.cpp 18.9 KB
Newer Older
1
2
3
/* ============================================================
 *
 * This file is a part of kipi-plugins project
4
 * http://www.digikam.org
5
6
7
8
9
 *
 * Date        : 2010-02-15
 * Description : a plugin to export to a remote Piwigo server.
 *
 * Copyright (C) 2003-2005 by Renchi Raju <renchi dot raju at gmail dot com>
Gilles Caulier's avatar
Gilles Caulier committed
10
 * Copyright (C) 2006      by Colin Guthrie <kde@colin.guthr.ie>
Gilles Caulier's avatar
Gilles Caulier committed
11
 * Copyright (C) 2006-2012 by Gilles Caulier <caulier dot gilles at gmail dot com>
Gilles Caulier's avatar
Gilles Caulier committed
12
13
 * Copyright (C) 2008      by Andrea Diamantini <adjam7 at gmail dot com>
 * Copyright (C) 2010      by Frederic Coiffier <frederic dot coiffier at free dot com>
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
 *
 * 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 "piwigowindow.moc"

// Qt includes

31
#include <Qt>
32
33
34
35
36
37
38
39
40
41
#include <QCheckBox>
#include <QDialog>
#include <QFileInfo>
#include <QGroupBox>
#include <QPushButton>
#include <QSpinBox>
#include <QTreeWidgetItem>
#include <QPointer>
#include <QHBoxLayout>
#include <QVBoxLayout>
42
43
44
#include <QTextStream>
#include <QFile>
#include <QProgressDialog>
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64

// KDE includes

#include <kaboutdata.h>
#include <kapplication.h>
#include <kconfig.h>
#include <kdebug.h>
#include <kicon.h>
#include <klocale.h>
#include <kmenu.h>
#include <kmessagebox.h>
#include <kpushbutton.h>
#include <krun.h>
#include <ktoolinvocation.h>
#include <kurllabel.h>
#include <kstandarddirs.h>

// LibKIPI includes

#include <libkipi/interface.h>
Gilles Caulier's avatar
compile    
Gilles Caulier committed
65
#include <libkipi/imagecollection.h>
66
67
68
69
70
71
72

// Local includes

#include "piwigos.h"
#include "piwigoconfig.h"
#include "piwigoitem.h"
#include "piwigotalker.h"
Gilles Caulier's avatar
Gilles Caulier committed
73
#include "kpimagedialog.h"
74
75
76
77
78
79
80
81
82
#include "kpaboutdata.h"

namespace KIPIPiwigoExportPlugin
{

class PiwigoWindow::Private
{
public:

Gilles Caulier's avatar
Gilles Caulier committed
83
    Private(PiwigoWindow* const parent);
84
85
86
87
88

    QWidget*               widget;

    QTreeWidget*           albumView;

89
    QPushButton*           confButton;
90
91

    QCheckBox*             resizeCheckBox;
92
93
    QSpinBox*              widthSpinBox;
    QSpinBox*              heightSpinBox;
94
95
96
97
98
    QSpinBox*              thumbDimensionSpinBox;

    QHash<QString, GAlbum> albumDict;

    KUrlLabel*             logo;
99
100
101
102
103
104
105
106
107

    PiwigoTalker*          talker;
    Piwigo*                pPiwigo;

    QProgressDialog*       progressDlg;
    unsigned int           uploadCount;
    unsigned int           uploadTotal;
    QStringList*           pUploadList;

108
109
};

Gilles Caulier's avatar
Gilles Caulier committed
110
PiwigoWindow::Private::Private(PiwigoWindow* const parent)
111
112
113
114
115
{
    widget = new QWidget(parent);
    parent->setMainWidget(widget);
    parent->setModal(false);

Gilles Caulier's avatar
Gilles Caulier committed
116
    QHBoxLayout* hlay = new QHBoxLayout(widget);
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134

    // ---------------------------------------------------------------------------

    logo = new KUrlLabel;
    logo->setText(QString());
    logo->setUrl("http://piwigo.org");
    logo->setPixmap(QPixmap(KStandardDirs::locate("data", "kipiplugin_piwigoexport/pics/piwigo_logo.png")));
    logo->setAlignment(Qt::AlignLeft);

    // ---------------------------------------------------------------------------

    albumView = new QTreeWidget;
    QStringList labels;
    labels << i18n("Albums");
    albumView->setHeaderLabels(labels);

    // ---------------------------------------------------------------------------

135
136
    QFrame* optionFrame = new QFrame;
    QVBoxLayout* vlay   = new QVBoxLayout();
137

138
139
140
141
    confButton = new QPushButton;
    confButton->setText(i18n("Change Account"));
    confButton->setIcon(KIcon("system-switch-user"));
    confButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
142

143
144
    QGroupBox* optionsBox = new QGroupBox(i18n("Options"));
    QVBoxLayout* vlay2    = new QVBoxLayout();
145
146
147
148

    resizeCheckBox        = new QCheckBox(optionsBox);
    resizeCheckBox->setText(i18n("Resize photos before uploading"));

149
150
    QGridLayout* glay     = new QGridLayout;
    QLabel* widthLabel    = new QLabel(i18n("Maximum width:"));
151
152
153
154
155
156

    widthSpinBox          = new QSpinBox;
    widthSpinBox->setRange(1,1600);
    widthSpinBox->setValue(800);

    QLabel *heightLabel   = new QLabel(i18n("Maximum height:"));
157

158
159
160
    heightSpinBox         = new QSpinBox;
    heightSpinBox->setRange(1,1600);
    heightSpinBox->setValue(600);
161

162
163
    QHBoxLayout* hlay2    = new QHBoxLayout;
    QLabel* resizeThumbLabel= new QLabel(i18n("Maximum thumbnail dimension:"));
164
165
166
167

    thumbDimensionSpinBox = new QSpinBox;
    thumbDimensionSpinBox->setRange(32,800);
    thumbDimensionSpinBox->setValue(128);
168
    thumbDimensionSpinBox->setToolTip(i18n("Thumbnail size is ignored with Piwigo > 2.4"));
169
170

    resizeCheckBox->setChecked(false);
171
172
    widthSpinBox->setEnabled(false);
    heightSpinBox->setEnabled(false);
173
174
175
176
    thumbDimensionSpinBox->setEnabled(true);

    // ---------------------------------------------------------------------------

177
178
179
180
    glay->addWidget(widthLabel, 0, 0);
    glay->addWidget(widthSpinBox, 0, 1);
    glay->addWidget(heightLabel, 1, 0);
    glay->addWidget(heightSpinBox, 1, 1);
Gilles Caulier's avatar
Gilles Caulier committed
181
182
    glay->setSpacing(spacingHint());
    glay->setMargin(spacingHint());
183
184
185

    // ---------------------------------------------------------------------------

186
187
    hlay2->addWidget(resizeThumbLabel);
    hlay2->addWidget(thumbDimensionSpinBox);
Gilles Caulier's avatar
Gilles Caulier committed
188
189
    hlay2->setSpacing(spacingHint());
    hlay2->setMargin(spacingHint());
190
191
192
193

    // ---------------------------------------------------------------------------

    vlay2->addWidget(resizeCheckBox);
194
    vlay2->addLayout(glay);
195
    vlay2->addLayout(hlay2);
196
    vlay2->addStretch(0);
Gilles Caulier's avatar
Gilles Caulier committed
197
198
    vlay2->setSpacing(spacingHint());
    vlay2->setMargin(spacingHint());
199
200
201
202
203

    optionsBox->setLayout(vlay2);

    // ---------------------------------------------------------------------------

204
    vlay->addWidget(confButton);
205
    vlay->addWidget(optionsBox);
Gilles Caulier's avatar
Gilles Caulier committed
206
207
    vlay->setSpacing(spacingHint());
    vlay->setMargin(spacingHint());
208
209
210
211
212
213
214
215

    optionFrame->setLayout(vlay);

    // ---------------------------------------------------------------------------

    hlay->addWidget(logo);
    hlay->addWidget(albumView);
    hlay->addWidget(optionFrame);
Gilles Caulier's avatar
Gilles Caulier committed
216
217
    hlay->setSpacing(spacingHint());
    hlay->setMargin(spacingHint());
218
219
220
221
222
223

    widget->setLayout(hlay);
}

// --------------------------------------------------------------------------------------------------------------

Gilles Caulier's avatar
Gilles Caulier committed
224
PiwigoWindow::PiwigoWindow(QWidget* const parent, Piwigo* const pPiwigo)
Gilles Caulier's avatar
Gilles Caulier committed
225
    : KPToolDialog(parent), 
Gilles Caulier's avatar
Gilles Caulier committed
226
      d(new Private(this))
227
{
Gilles Caulier's avatar
Gilles Caulier committed
228
    d->pPiwigo = pPiwigo;
229

230
    setWindowTitle( i18n("Piwigo Export") );
Gilles Caulier's avatar
Gilles Caulier committed
231
    setButtons(Close | User1 | Help);
232
233
234
    setModal(false);

    // About data.
Gilles Caulier's avatar
Gilles Caulier committed
235
236
237
238
239
240
241
242
243
    KPAboutData* about = new KPAboutData(ki18n("Piwigo Export"),
                                         0,
                                         KAboutData::License_GPL,
                                         ki18n("A Kipi plugin to export image collections to a remote Piwigo server."),
                                         ki18n("(c) 2003-2005, Renchi Raju\n"
                                               "(c) 2006-2007, Colin Guthrie\n"
                                               "(c) 2006-2012, Gilles Caulier\n"
                                               "(c) 2008, Andrea Diamantini\n"
                                               "(c) 2012, Frédéric Coiffier\n"));
244

Gilles Caulier's avatar
Gilles Caulier committed
245
246
    about->addAuthor(ki18n("Renchi Raju"), ki18n("Author"),
                     "renchi dot raju at gmail dot com");
247

Gilles Caulier's avatar
Gilles Caulier committed
248
249
    about->addAuthor(ki18n("Colin Guthrie"), ki18n("Maintainer"),
                     "kde at colin dot guthr dot ie");
250

Gilles Caulier's avatar
Gilles Caulier committed
251
252
    about->addAuthor(ki18n("Andrea Diamantini"), ki18n("Developer"),
                     "adjam7 at gmail dot com");
253

Gilles Caulier's avatar
Gilles Caulier committed
254
255
    about->addAuthor(ki18n("Gilles Caulier"), ki18n("Developer"),
                     "caulier dot gilles at gmail dot com");
256

Gilles Caulier's avatar
Gilles Caulier committed
257
258
    about->addAuthor(ki18n("Frédéric Coiffier"), ki18n("Developer"),
                     "fcoiffie at gmail dot com");
259

260
    about->setHandbookEntry("piwigoexport");
Gilles Caulier's avatar
Gilles Caulier committed
261
    setAboutData(about);
262

263
    // User1 Button : to upload selected photos
Gilles Caulier's avatar
Gilles Caulier committed
264
    KPushButton* addPhotoBtn = button( User1 );
265
266
267
268
269
    addPhotoBtn->setText( i18n("Start Upload") );
    addPhotoBtn->setIcon( KIcon("network-workgroup") );
    addPhotoBtn->setEnabled(false);
    connect(addPhotoBtn, SIGNAL(clicked()),
            this, SLOT(slotAddPhoto()));
270

271
272
    // we need to let d->talker work..
    d->talker = new PiwigoTalker(d->widget);
273
274

    // setting progressDlg and its numeric hints
275
276
277
278
279
280
281
    d->progressDlg = new QProgressDialog(this);
    d->progressDlg->setModal(true);
    d->progressDlg->setAutoReset(true);
    d->progressDlg->setAutoClose(true);
    d->uploadCount = 0;
    d->uploadTotal = 0;
    d->pUploadList = new QStringList;
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298

    // connect functions
    connectSignals();

    // read Settings
    readSettings();

    slotDoLogin();
}

PiwigoWindow::~PiwigoWindow()
{
    // write config
    KConfig config("kipirc");
    KConfigGroup group = config.group("PiwigoSync Galleries");

    group.writeEntry("Resize",          d->resizeCheckBox->isChecked());
299
300
    group.writeEntry("Maximum Width",   d->widthSpinBox->value());
    group.writeEntry("Maximum Height",  d->heightSpinBox->value());
301
302
    group.writeEntry("Thumbnail Width", d->thumbDimensionSpinBox->value());

303
304
    delete d->talker;
    delete d->pUploadList;
305
306
307
308
309
310
    delete d;
}

void PiwigoWindow::connectSignals()
{
    connect(d->albumView, SIGNAL(itemSelectionChanged()),
Laurent Montel's avatar
Laurent Montel committed
311
            this , SLOT(slotAlbumSelected()) );
312

313
314
    connect(d->confButton, SIGNAL(clicked()), 
             this, SLOT(slotSettings()) );
315
316
317
318

    connect(d->resizeCheckBox, SIGNAL(stateChanged(int)),
            this, SLOT(slotEnableSpinBox(int)));

Laurent Montel's avatar
Laurent Montel committed
319
320
    connect(d->logo, SIGNAL(leftClickedUrl(QString)),
            this, SLOT(slotProcessUrl(QString)));
321

322
    connect(d->progressDlg, SIGNAL(canceled()),
Laurent Montel's avatar
Laurent Montel committed
323
            this, SLOT(slotAddPhotoCancel()));
324

325
    connect(d->talker, SIGNAL(signalProgressInfo(QString)),
Laurent Montel's avatar
Laurent Montel committed
326
            this, SLOT(slotProgressInfo(QString)));
327

328
    connect(d->talker, SIGNAL(signalError(QString)),
Laurent Montel's avatar
Laurent Montel committed
329
            this, SLOT(slotError(QString)));
330

331
    connect(d->talker, SIGNAL(signalBusy(bool)),
332
333
            this, SLOT(slotBusy(bool)));

334
    connect(d->talker, SIGNAL(signalLoginFailed(QString)),
Laurent Montel's avatar
Laurent Montel committed
335
            this, SLOT(slotLoginFailed(QString)));
336

337
    connect(d->talker, SIGNAL(signalAlbums(QList<GAlbum>)),
Laurent Montel's avatar
Laurent Montel committed
338
            this, SLOT(slotAlbums(QList<GAlbum>)));
339

340
    connect(d->talker, SIGNAL(signalAddPhotoSucceeded()),
341
342
            this, SLOT(slotAddPhotoSucceeded()));

343
    connect(d->talker, SIGNAL(signalAddPhotoFailed(QString)),
Laurent Montel's avatar
Laurent Montel committed
344
            this, SLOT(slotAddPhotoFailed(QString)));
345
346
347
348
349
350
351
352
353
354
355
356
357
}

void PiwigoWindow::slotProcessUrl(const QString& url)
{
    KToolInvocation::self()->invokeBrowser(url);
}

void PiwigoWindow::readSettings()
{
    // read Config
    KConfig config("kipirc");
    KConfigGroup group = config.group("PiwigoSync Galleries");

Gilles Caulier's avatar
Gilles Caulier committed
358
359
    if (group.readEntry("Resize", false))
    {
360
        d->resizeCheckBox->setChecked(true);
361
362
        d->widthSpinBox->setEnabled(true);
        d->heightSpinBox->setEnabled(true);
Gilles Caulier's avatar
Gilles Caulier committed
363
364
365
    }
    else
    {
366
        d->resizeCheckBox->setChecked(false);
367
368
        d->heightSpinBox->setEnabled(false);
        d->widthSpinBox->setEnabled(false);
369
370
    }

371
372
373
    d->widthSpinBox->setValue(group.readEntry("Maximum Width", 800));
    d->heightSpinBox->setValue(group.readEntry("Maximum Height", 600));

374
375
376
377
378
    d->thumbDimensionSpinBox->setValue(group.readEntry("Thumbnail Width", 128));
}

void PiwigoWindow::slotDoLogin()
{
379
    KUrl url(d->pPiwigo->url());
Gilles Caulier's avatar
Gilles Caulier committed
380
381
    if (url.protocol().isEmpty())
    {
382
        url.setProtocol("http");
383
        url.setHost(d->pPiwigo->url());
384
385
386
    }

    // If we've done something clever, save it back to the piwigo.
387
    if (!url.url().isEmpty() && d->pPiwigo->url() != url.url())
Gilles Caulier's avatar
Gilles Caulier committed
388
    {
389
390
        d->pPiwigo->setUrl(url.url());
        d->pPiwigo->save();
391
392
    }

393
    d->talker->login(url.url(), d->pPiwigo->username(), d->pPiwigo->password());
394
395
396
397
398
399
400
401
}

void PiwigoWindow::slotLoginFailed(const QString& msg)
{
    if (KMessageBox::warningYesNo(this,
                                  i18n("Failed to login into remote piwigo. ")
                                  + msg
                                  + i18n("\nDo you want to check your settings and try again?"))
Gilles Caulier's avatar
Gilles Caulier committed
402
403
            != KMessageBox::Yes)
    {
404
405
406
407
        close();
        return;
    }

408
    QPointer<PiwigoEdit> configDlg = new PiwigoEdit(kapp->activeWindow(), d->pPiwigo, i18n("Edit Piwigo Data") );
Gilles Caulier's avatar
Gilles Caulier committed
409
410
    if ( configDlg->exec() != QDialog::Accepted )
    {
411
412
413
414
415
416
417
418
419
        delete configDlg;
        return;
    }
    slotDoLogin();
    delete configDlg;
}

void PiwigoWindow::slotBusy(bool val)
{
Gilles Caulier's avatar
Gilles Caulier committed
420
421
    if (val)
    {
422
        setCursor(Qt::WaitCursor);
423
        button( User1 )->setEnabled(false);
Gilles Caulier's avatar
Gilles Caulier committed
424
425
426
    }
    else
    {
427
        setCursor(Qt::ArrowCursor);
428
        bool loggedIn = d->talker->loggedIn();
429
        button( User1 )->setEnabled(loggedIn && d->albumView->currentItem());
430
431
432
    }
}

433
434
void PiwigoWindow::slotProgressInfo(const QString& msg)
{
435
    d->progressDlg->setLabelText(msg);
436
437
}

438
439
void PiwigoWindow::slotError(const QString& msg)
{
440
    d->progressDlg->hide();
441
442
443
444
445
446
447
448
449
450
451
452
453
    KMessageBox::error(this, msg);
}

void PiwigoWindow::slotAlbums(const QList<GAlbum>& albumList)
{
    d->albumDict.clear();
    d->albumView->clear();

    // album work list
    QList<GAlbum> workList(albumList);
    QList<QTreeWidgetItem *> parentItemList;

    // fill QTreeWidget
Gilles Caulier's avatar
Gilles Caulier committed
454
455
    while ( !workList.isEmpty() )
    {
456
457
458
459
        // the album to work on
        GAlbum album = workList.takeFirst();

        int parentRefNum = album.parent_ref_num;
Gilles Caulier's avatar
Gilles Caulier committed
460
461
        if ( parentRefNum == -1 )
        {
462
463
464
465
466
467
468
469
470
471
472
            QTreeWidgetItem *item = new QTreeWidgetItem();
            item->setText(0, cleanName(album.name) );
            item->setIcon(0, KIcon("inode-directory") );
            item->setData(1, Qt::UserRole, QVariant(album.ref_num) );
            item->setText(2, i18n("Album") );

            kDebug() << "Top : " << album.name << " " << album.ref_num << "\n";

            d->albumView->addTopLevelItem(item);
            d->albumDict.insert(album.name, album);
            parentItemList << item;
Gilles Caulier's avatar
Gilles Caulier committed
473
474
475
        }
        else
        {
476
477
478
479
            QTreeWidgetItem *parentItem = 0;
            bool found                  = false;
            int i                       = 0;

Gilles Caulier's avatar
Gilles Caulier committed
480
481
            while ( !found && i < parentItemList.size() )
            {
482
483
                parentItem = parentItemList.at(i);

Gilles Caulier's avatar
Gilles Caulier committed
484
485
                if (parentItem && (parentItem->data(1, Qt::UserRole).toInt() == parentRefNum))
                {
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
                    QTreeWidgetItem *item = new QTreeWidgetItem(parentItem);
                    item->setText(0, cleanName(album.name) );
                    item->setIcon(0, KIcon("inode-directory") );
                    item->setData(1, Qt::UserRole, album.ref_num );
                    item->setText(2, i18n("Album") );

                    parentItem->addChild(item);
                    d->albumDict.insert(album.name, album);
                    parentItemList << item;
                    found = true;
                }
                i++;
            }
        }
    }
}

void PiwigoWindow::slotAlbumSelected()
{
    QTreeWidgetItem* item = d->albumView->currentItem();
506
507
508
509
    if (!item)
    {
        return;
    }
510
511
512
513
514

    // stop loading if user clicked an image
    if ( item->text(2) == i18n("Image") )
        return;

Gilles Caulier's avatar
Gilles Caulier committed
515
516
    if (!item)
    {
517
        button( User1 )->setEnabled(false);
Gilles Caulier's avatar
Gilles Caulier committed
518
519
520
    }
    else
    {
521
522
523
524
        kDebug() << "Album selected\n";

        int albumId = item->data(1, Qt::UserRole).toInt();
        kDebug() << albumId << "\n";
525
        if (d->talker->loggedIn() && albumId )
Gilles Caulier's avatar
Gilles Caulier committed
526
        {
527
            button( User1 )->setEnabled(true);
Gilles Caulier's avatar
Gilles Caulier committed
528
529
530
        }
        else
        {
531
            button( User1 )->setEnabled(false);
532
533
534
535
536
537
        }
    }
}

void PiwigoWindow::slotAddPhoto()
{
Gilles Caulier's avatar
Gilles Caulier committed
538
    const KUrl::List urls(iface()->currentSelection().images());
539

Gilles Caulier's avatar
Gilles Caulier committed
540
541
    if ( urls.isEmpty())
    {
542
543
544
545
        KMessageBox::error(this, i18n("Nothing to upload - please select photos to upload."));
        return;
    }

Gilles Caulier's avatar
Gilles Caulier committed
546
547
    for (KUrl::List::const_iterator it = urls.constBegin(); it != urls.constEnd(); ++it)
    {
548
        d->pUploadList->append( (*it).path() );
549
550
    }

551
552
553
554
    d->uploadTotal = d->pUploadList->count();
    d->progressDlg->reset();
    d->progressDlg->setMaximum(d->uploadTotal);
    d->uploadCount = 0;
555
556
557
558
559
    slotAddPhotoNext();
}

void PiwigoWindow::slotAddPhotoNext()
{
560
    if ( d->pUploadList->isEmpty() )
Gilles Caulier's avatar
Gilles Caulier committed
561
    {
562
563
        d->progressDlg->reset();
        d->progressDlg->hide();
564
565
566
567
568
569
570
        return;
    }

    QTreeWidgetItem* item = d->albumView->currentItem();
    int column            = d->albumView->currentColumn();
    QString albumTitle    = item->text(column);
    const GAlbum& album   = d->albumDict.value(albumTitle);
571
572
    QString photoPath     = d->pUploadList->takeFirst();
    bool res              = d->talker->addPhoto(album.ref_num, photoPath,
573
                            d->resizeCheckBox->isChecked(),
574
575
                            d->widthSpinBox->value(),
                            d->heightSpinBox->value(),
576
577
                            d->thumbDimensionSpinBox->value() );

Gilles Caulier's avatar
Gilles Caulier committed
578
579
    if (!res)
    {
580
581
582
583
        slotAddPhotoFailed( "" );
        return;
    }

584
    d->progressDlg->setLabelText( i18n("Uploading file %1", KUrl(photoPath).fileName()) );
585

586
587
    if (d->progressDlg->isHidden())
        d->progressDlg->show();
588
589
590
591
}

void PiwigoWindow::slotAddPhotoSucceeded()
{
592
593
    d->uploadCount++;
    d->progressDlg->setValue(d->uploadCount);
594
595
596
597
598
    slotAddPhotoNext();
}

void PiwigoWindow::slotAddPhotoFailed(const QString& msg)
{
599
600
    d->progressDlg->reset();
    d->progressDlg->hide();
601
602
603
604
605
606

    if (KMessageBox::warningContinueCancel(this,
                                           i18n("Failed to upload photo into "
                                                "remote piwigo. ")
                                           + msg
                                           + i18n("\nDo you want to continue?"))
Gilles Caulier's avatar
Gilles Caulier committed
607
608
609
610
611
612
            != KMessageBox::Continue)
    {
        return;
    }
    else
    {
613
614
615
616
617
618
        slotAddPhotoNext();
    }
}

void PiwigoWindow::slotAddPhotoCancel()
{
619
620
621
    d->progressDlg->reset();
    d->progressDlg->hide();
    d->talker->cancel();
622
623
624
625
626
}

void PiwigoWindow::slotEnableSpinBox(int n)
{
    bool b;
Gilles Caulier's avatar
Gilles Caulier committed
627
628
    switch (n)
    {
Gilles Caulier's avatar
Gilles Caulier committed
629
630
631
632
633
634
635
636
637
638
        case 0:
            b = false;
            break;
        case 1:
        case 2:
            b = true;
            break;
        default:
            b = false;
            break;
639
    }
640
641
    d->widthSpinBox->setEnabled(b);
    d->heightSpinBox->setEnabled(b);
642
643
644
645
646
}

void PiwigoWindow::slotSettings()
{
    // TODO: reload albumlist if OK slot used.
647
    QPointer<PiwigoEdit> dlg = new PiwigoEdit(kapp->activeWindow(), d->pPiwigo, i18n("Edit Piwigo Data") );
Gilles Caulier's avatar
Gilles Caulier committed
648
649
    if ( dlg->exec() == QDialog::Accepted )
    {
650
651
652
653
654
        slotDoLogin();
    }
    delete dlg;
}

Gilles Caulier's avatar
Gilles Caulier committed
655
QString PiwigoWindow::cleanName(const QString& str) const
656
657
658
659
660
661
662
663
664
665
666
{
    QString plain = str;
    plain.replace("&lt;", "<");
    plain.replace("&gt;", ">");
    plain.replace("&quot;", "\"");
    plain.replace("&amp;", "&");

    return plain;
}

} // namespace KIPIPiwigoExportPlugin