| 1 | /* ============================================================ |
|---|
| 2 | * |
|---|
| 3 | * This file is a part of kipi-plugins project |
|---|
| 4 | * http://www.kipi-plugins.org |
|---|
| 5 | * |
|---|
| 6 | * Date : 2010-01-07 |
|---|
| 7 | * Description : a plugin to export to a remote Piwigo server. |
|---|
| 8 | * |
|---|
| 9 | * Copyright (C) 2003-2005 by Renchi Raju <renchi dot raju at gmail dot com> |
|---|
| 10 | * Copyright (C) 2006 by Colin Guthrie <kde@colin.guthr.ie> |
|---|
| 11 | * Copyright (C) 2006-2009 by Gilles Caulier <caulier dot gilles at gmail dot com> |
|---|
| 12 | * Copyright (C) 2008 by Andrea Diamantini <adjam7 at gmail dot com> |
|---|
| 13 | * Copyright (C) 2010 by Frederic Coiffier <frederic dot coiffier at free dot com> |
|---|
| 14 | * |
|---|
| 15 | * This program is free software; you can redistribute it |
|---|
| 16 | * and/or modify it under the terms of the GNU General |
|---|
| 17 | * Public License as published by the Free Software Foundation; |
|---|
| 18 | * either version 2, or (at your option) any later version. |
|---|
| 19 | * |
|---|
| 20 | * This program is distributed in the hope that it will be useful, |
|---|
| 21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 23 | * GNU General Public License for more details. |
|---|
| 24 | * |
|---|
| 25 | * ============================================================ */ |
|---|
| 26 | |
|---|
| 27 | #include "piwigowindow.h" |
|---|
| 28 | #include "piwigowindow.moc" |
|---|
| 29 | |
|---|
| 30 | // Qt includes |
|---|
| 31 | |
|---|
| 32 | #include <QCheckBox> |
|---|
| 33 | #include <QDialog> |
|---|
| 34 | #include <QFileInfo> |
|---|
| 35 | #include <QGroupBox> |
|---|
| 36 | #include <QPushButton> |
|---|
| 37 | #include <QSpinBox> |
|---|
| 38 | #include <Qt> |
|---|
| 39 | #include <QTreeWidgetItem> |
|---|
| 40 | #include <QPointer> |
|---|
| 41 | |
|---|
| 42 | // KDE includes |
|---|
| 43 | |
|---|
| 44 | #include <kaboutdata.h> |
|---|
| 45 | #include <kapplication.h> |
|---|
| 46 | #include <kconfig.h> |
|---|
| 47 | #include <kdebug.h> |
|---|
| 48 | #include <khelpmenu.h> |
|---|
| 49 | #include <kicon.h> |
|---|
| 50 | #include <klocale.h> |
|---|
| 51 | #include <kmenu.h> |
|---|
| 52 | #include <kmessagebox.h> |
|---|
| 53 | #include <kpushbutton.h> |
|---|
| 54 | #include <krun.h> |
|---|
| 55 | #include <ktoolinvocation.h> |
|---|
| 56 | #include <kurllabel.h> |
|---|
| 57 | #include <kstandarddirs.h> |
|---|
| 58 | |
|---|
| 59 | // LibKIPI includes |
|---|
| 60 | |
|---|
| 61 | #include <libkipi/interface.h> |
|---|
| 62 | |
|---|
| 63 | // Local includes |
|---|
| 64 | |
|---|
| 65 | #include "albumdlg.h" |
|---|
| 66 | #include "piwigos.h" |
|---|
| 67 | #include "piwigoconfig.h" |
|---|
| 68 | #include "piwigoitem.h" |
|---|
| 69 | #include "piwigotalker.h" |
|---|
| 70 | #include "imagedialog.h" |
|---|
| 71 | #include "kpaboutdata.h" |
|---|
| 72 | |
|---|
| 73 | namespace KIPIPiwigoExportPlugin |
|---|
| 74 | { |
|---|
| 75 | |
|---|
| 76 | class PiwigoWindow::Private |
|---|
| 77 | { |
|---|
| 78 | public: |
|---|
| 79 | |
|---|
| 80 | Private(PiwigoWindow* parent); |
|---|
| 81 | |
|---|
| 82 | QWidget* widget; |
|---|
| 83 | |
|---|
| 84 | QTreeWidget* albumView; |
|---|
| 85 | |
|---|
| 86 | QPushButton* newAlbumBtn; |
|---|
| 87 | QPushButton* addPhotoBtn; |
|---|
| 88 | |
|---|
| 89 | QCheckBox* captTitleCheckBox; |
|---|
| 90 | QCheckBox* captDescrCheckBox; |
|---|
| 91 | QCheckBox* resizeCheckBox; |
|---|
| 92 | |
|---|
| 93 | QSpinBox* dimensionSpinBox; |
|---|
| 94 | QSpinBox* thumbDimensionSpinBox; |
|---|
| 95 | |
|---|
| 96 | QHash<QString, GAlbum> albumDict; |
|---|
| 97 | |
|---|
| 98 | KUrlLabel* logo; |
|---|
| 99 | }; |
|---|
| 100 | |
|---|
| 101 | PiwigoWindow::Private::Private(PiwigoWindow* parent) |
|---|
| 102 | { |
|---|
| 103 | widget = new QWidget(parent); |
|---|
| 104 | parent->setMainWidget(widget); |
|---|
| 105 | parent->setModal(false); |
|---|
| 106 | |
|---|
| 107 | QHBoxLayout *hlay = new QHBoxLayout(widget); |
|---|
| 108 | |
|---|
| 109 | // --------------------------------------------------------------------------- |
|---|
| 110 | |
|---|
| 111 | logo = new KUrlLabel; |
|---|
| 112 | logo->setText(QString()); |
|---|
| 113 | logo->setUrl("http://piwigo.menalto.com"); |
|---|
| 114 | logo->setPixmap(QPixmap(KStandardDirs::locate("data", "kipiplugin_piwigoexport/pics/piwigo_logo.png"))); |
|---|
| 115 | logo->setAlignment(Qt::AlignLeft); |
|---|
| 116 | |
|---|
| 117 | // --------------------------------------------------------------------------- |
|---|
| 118 | |
|---|
| 119 | albumView = new QTreeWidget; |
|---|
| 120 | QStringList labels; |
|---|
| 121 | labels << i18n("Albums"); // << i18n("ID"); |
|---|
| 122 | albumView->setHeaderLabels(labels); |
|---|
| 123 | |
|---|
| 124 | // --------------------------------------------------------------------------- |
|---|
| 125 | |
|---|
| 126 | QFrame *optionFrame = new QFrame; |
|---|
| 127 | QVBoxLayout *vlay = new QVBoxLayout(); |
|---|
| 128 | |
|---|
| 129 | newAlbumBtn = new QPushButton; |
|---|
| 130 | newAlbumBtn->setText(i18n("&New Album")); |
|---|
| 131 | newAlbumBtn->setIcon(KIcon("folder-new")); |
|---|
| 132 | newAlbumBtn->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); |
|---|
| 133 | newAlbumBtn->setEnabled(false); |
|---|
| 134 | |
|---|
| 135 | addPhotoBtn = new QPushButton; |
|---|
| 136 | addPhotoBtn->setText(i18n("&Add Selected Photos")); |
|---|
| 137 | addPhotoBtn->setIcon(KIcon("list-add")); |
|---|
| 138 | addPhotoBtn->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); |
|---|
| 139 | addPhotoBtn->setEnabled(false); |
|---|
| 140 | |
|---|
| 141 | QGroupBox *optionsBox = new QGroupBox(i18n("Override Default Options")); |
|---|
| 142 | QVBoxLayout *vlay2 = new QVBoxLayout(); |
|---|
| 143 | |
|---|
| 144 | captTitleCheckBox = new QCheckBox(optionsBox); |
|---|
| 145 | captTitleCheckBox->setText(i18n("EXIF Comment (instead of file name) sets Title")); |
|---|
| 146 | |
|---|
| 147 | captDescrCheckBox = new QCheckBox(optionsBox); |
|---|
| 148 | captDescrCheckBox->setText(i18n("EXIF Comment (instead of file name) sets Comment")); |
|---|
| 149 | |
|---|
| 150 | resizeCheckBox = new QCheckBox(optionsBox); |
|---|
| 151 | resizeCheckBox->setText(i18n("Resize photos before uploading")); |
|---|
| 152 | |
|---|
| 153 | QHBoxLayout *hlay2 = new QHBoxLayout; |
|---|
| 154 | QLabel *resizeLabel = new QLabel(i18n("Maximum dimension:")); |
|---|
| 155 | |
|---|
| 156 | dimensionSpinBox = new QSpinBox; |
|---|
| 157 | dimensionSpinBox->setRange(1,1600); |
|---|
| 158 | dimensionSpinBox->setValue(600); |
|---|
| 159 | |
|---|
| 160 | QHBoxLayout *hlay3 = new QHBoxLayout; |
|---|
| 161 | QLabel *resizeThumbLabel= new QLabel(i18n("Maximum thumbnail dimension:")); |
|---|
| 162 | |
|---|
| 163 | thumbDimensionSpinBox = new QSpinBox; |
|---|
| 164 | thumbDimensionSpinBox->setRange(32,800); |
|---|
| 165 | thumbDimensionSpinBox->setValue(120); |
|---|
| 166 | |
|---|
| 167 | captTitleCheckBox->setChecked(true); |
|---|
| 168 | captDescrCheckBox->setChecked(false); |
|---|
| 169 | resizeCheckBox->setChecked(false); |
|---|
| 170 | dimensionSpinBox->setEnabled(false); |
|---|
| 171 | thumbDimensionSpinBox->setEnabled(true); |
|---|
| 172 | |
|---|
| 173 | // --------------------------------------------------------------------------- |
|---|
| 174 | |
|---|
| 175 | hlay2->addWidget(resizeLabel); |
|---|
| 176 | hlay2->addWidget(dimensionSpinBox); |
|---|
| 177 | hlay2->setSpacing(KDialog::spacingHint()); |
|---|
| 178 | hlay2->setMargin(KDialog::spacingHint()); |
|---|
| 179 | |
|---|
| 180 | // --------------------------------------------------------------------------- |
|---|
| 181 | |
|---|
| 182 | hlay3->addWidget(resizeThumbLabel); |
|---|
| 183 | hlay3->addWidget(thumbDimensionSpinBox); |
|---|
| 184 | hlay3->setSpacing(KDialog::spacingHint()); |
|---|
| 185 | hlay3->setMargin(KDialog::spacingHint()); |
|---|
| 186 | |
|---|
| 187 | // --------------------------------------------------------------------------- |
|---|
| 188 | |
|---|
| 189 | vlay2->addWidget(captTitleCheckBox); |
|---|
| 190 | vlay2->addWidget(captDescrCheckBox); |
|---|
| 191 | vlay2->addWidget(resizeCheckBox); |
|---|
| 192 | vlay2->addLayout(hlay2); |
|---|
| 193 | vlay2->addLayout(hlay3); |
|---|
| 194 | vlay2->setSpacing(KDialog::spacingHint()); |
|---|
| 195 | vlay2->setMargin(KDialog::spacingHint()); |
|---|
| 196 | |
|---|
| 197 | optionsBox->setLayout(vlay2); |
|---|
| 198 | |
|---|
| 199 | // --------------------------------------------------------------------------- |
|---|
| 200 | |
|---|
| 201 | vlay->addWidget(newAlbumBtn); |
|---|
| 202 | vlay->addWidget(addPhotoBtn); |
|---|
| 203 | vlay->addWidget(optionsBox); |
|---|
| 204 | vlay->setSpacing(KDialog::spacingHint()); |
|---|
| 205 | vlay->setMargin(KDialog::spacingHint()); |
|---|
| 206 | |
|---|
| 207 | optionFrame->setLayout(vlay); |
|---|
| 208 | |
|---|
| 209 | // --------------------------------------------------------------------------- |
|---|
| 210 | |
|---|
| 211 | hlay->addWidget(logo); |
|---|
| 212 | hlay->addWidget(albumView); |
|---|
| 213 | hlay->addWidget(optionFrame); |
|---|
| 214 | hlay->setSpacing(KDialog::spacingHint()); |
|---|
| 215 | hlay->setMargin(KDialog::spacingHint()); |
|---|
| 216 | |
|---|
| 217 | widget->setLayout(hlay); |
|---|
| 218 | } |
|---|
| 219 | |
|---|
| 220 | // -------------------------------------------------------------------------------------------------------------- |
|---|
| 221 | |
|---|
| 222 | PiwigoWindow::PiwigoWindow(KIPI::Interface* interface, QWidget *parent, Piwigo* pPiwigo) |
|---|
| 223 | : KDialog(parent), |
|---|
| 224 | m_interface(interface), |
|---|
| 225 | mpPiwigo(pPiwigo), |
|---|
| 226 | d(new Private(this)) |
|---|
| 227 | { |
|---|
| 228 | kDebug() << "BEGIN Window\n"; |
|---|
| 229 | |
|---|
| 230 | |
|---|
| 231 | setWindowTitle( i18n("Piwigo Export") ); |
|---|
| 232 | setButtons( KDialog::Close | KDialog::User1 | KDialog::Help); |
|---|
| 233 | setModal(false); |
|---|
| 234 | |
|---|
| 235 | // About data. |
|---|
| 236 | m_about = new KIPIPlugins::KPAboutData(ki18n("Piwigo Export"), |
|---|
| 237 | 0, |
|---|
| 238 | KAboutData::License_GPL, |
|---|
| 239 | ki18n("A Kipi plugin to export image collections to a remote Piwigo server."), |
|---|
| 240 | ki18n("(c) 2003-2005, Renchi Raju\n" |
|---|
| 241 | "(c) 2006-2007, Colin Guthrie\n" |
|---|
| 242 | "(c) 2006-2009, Gilles Caulier\n" |
|---|
| 243 | "(c) 2008, Andrea Diamantini\n" |
|---|
| 244 | "(c) 2010, Frédéric Coiffier\n")); |
|---|
| 245 | |
|---|
| 246 | m_about->addAuthor(ki18n("Renchi Raju"), ki18n("Author"), |
|---|
| 247 | "renchi dot raju at gmail dot com"); |
|---|
| 248 | |
|---|
| 249 | m_about->addAuthor(ki18n("Colin Guthrie"), ki18n("Maintainer"), |
|---|
| 250 | "kde at colin dot guthr dot ie"); |
|---|
| 251 | |
|---|
| 252 | m_about->addAuthor(ki18n("Andrea Diamantini"), ki18n("Developer"), |
|---|
| 253 | "adjam7 at gmail dot com"); |
|---|
| 254 | |
|---|
| 255 | m_about->addAuthor(ki18n("Gilles Caulier"), ki18n("Developer"), |
|---|
| 256 | "caulier dot gilles at gmail dot com"); |
|---|
| 257 | |
|---|
| 258 | m_about->addAuthor(ki18n("Frédéric Coiffier"), ki18n("Developer"), |
|---|
| 259 | "fcoiffie at gmail dot com"); |
|---|
| 260 | |
|---|
| 261 | // help button |
|---|
| 262 | |
|---|
| 263 | disconnect(this, SIGNAL(helpClicked()), |
|---|
| 264 | this, SLOT(slotHelp())); |
|---|
| 265 | |
|---|
| 266 | KHelpMenu *helpMenu = new KHelpMenu(this, m_about, false); |
|---|
| 267 | helpMenu->menu()->removeAction(helpMenu->menu()->actions().first()); |
|---|
| 268 | QAction *handbook = new QAction(i18n("Handbook"), this); |
|---|
| 269 | connect(handbook, SIGNAL(triggered(bool)), |
|---|
| 270 | this, SLOT(slotHelp())); |
|---|
| 271 | helpMenu->menu()->insertAction(helpMenu->menu()->actions().first(), handbook); |
|---|
| 272 | button(Help)->setMenu(helpMenu->menu()); |
|---|
| 273 | |
|---|
| 274 | // User1 Button : to conf piwigo settings |
|---|
| 275 | KPushButton *confButton = button( User1 ); |
|---|
| 276 | confButton->setText( i18n("Settings") ); |
|---|
| 277 | confButton->setIcon( KIcon("configure") ); |
|---|
| 278 | connect(confButton, SIGNAL(clicked()), |
|---|
| 279 | this, SLOT(slotSettings() ) ); |
|---|
| 280 | |
|---|
| 281 | // we need to let m_talker work.. |
|---|
| 282 | m_talker = new PiwigoTalker(d->widget); |
|---|
| 283 | |
|---|
| 284 | // setting progressDlg and its numeric hints |
|---|
| 285 | m_progressDlg = new QProgressDialog(this); |
|---|
| 286 | m_progressDlg->setModal(true); |
|---|
| 287 | m_progressDlg->setAutoReset(true); |
|---|
| 288 | m_progressDlg->setAutoClose(true); |
|---|
| 289 | m_uploadCount = 0; |
|---|
| 290 | m_uploadTotal = 0; |
|---|
| 291 | mpUploadList = new QStringList; |
|---|
| 292 | |
|---|
| 293 | // connect functions |
|---|
| 294 | connectSignals(); |
|---|
| 295 | |
|---|
| 296 | // read Settings |
|---|
| 297 | readSettings(); |
|---|
| 298 | |
|---|
| 299 | slotDoLogin(); |
|---|
| 300 | } |
|---|
| 301 | |
|---|
| 302 | PiwigoWindow::~PiwigoWindow() |
|---|
| 303 | { |
|---|
| 304 | // write config |
|---|
| 305 | KConfig config("kipirc"); |
|---|
| 306 | KConfigGroup group = config.group("PiwigoSync Galleries"); |
|---|
| 307 | |
|---|
| 308 | group.writeEntry("Resize", d->resizeCheckBox->isChecked()); |
|---|
| 309 | group.writeEntry("Set title", d->captTitleCheckBox->isChecked()); |
|---|
| 310 | group.writeEntry("Set description", d->captDescrCheckBox->isChecked()); |
|---|
| 311 | group.writeEntry("Maximum Width", d->dimensionSpinBox->value()); |
|---|
| 312 | |
|---|
| 313 | delete m_talker; |
|---|
| 314 | |
|---|
| 315 | delete mpUploadList; |
|---|
| 316 | delete m_about; |
|---|
| 317 | |
|---|
| 318 | delete d; |
|---|
| 319 | } |
|---|
| 320 | |
|---|
| 321 | void PiwigoWindow::connectSignals() |
|---|
| 322 | { |
|---|
| 323 | connect(d->albumView, SIGNAL(itemSelectionChanged()), |
|---|
| 324 | this , SLOT( slotAlbumSelected() ) ); |
|---|
| 325 | |
|---|
| 326 | connect(d->newAlbumBtn, SIGNAL(clicked()), |
|---|
| 327 | this, SLOT(slotNewAlbum())); |
|---|
| 328 | |
|---|
| 329 | connect(d->addPhotoBtn, SIGNAL(clicked()), |
|---|
| 330 | this, SLOT(slotAddPhoto())); |
|---|
| 331 | |
|---|
| 332 | connect(d->resizeCheckBox, SIGNAL(stateChanged(int)), |
|---|
| 333 | this, SLOT(slotEnableSpinBox(int))); |
|---|
| 334 | |
|---|
| 335 | connect(d->logo, SIGNAL(leftClickedUrl(const QString&)), |
|---|
| 336 | this, SLOT(slotProcessUrl(const QString&))); |
|---|
| 337 | |
|---|
| 338 | connect(m_progressDlg, SIGNAL( canceled() ), |
|---|
| 339 | this, SLOT( slotAddPhotoCancel() )); |
|---|
| 340 | |
|---|
| 341 | connect(m_talker, SIGNAL(signalError(const QString&)), |
|---|
| 342 | this, SLOT(slotError(const QString&))); |
|---|
| 343 | |
|---|
| 344 | connect(m_talker, SIGNAL(signalBusy(bool)), |
|---|
| 345 | this, SLOT(slotBusy(bool))); |
|---|
| 346 | |
|---|
| 347 | connect(m_talker, SIGNAL(signalLoginFailed(const QString&)), |
|---|
| 348 | this, SLOT(slotLoginFailed(const QString&))); |
|---|
| 349 | |
|---|
| 350 | connect(m_talker, SIGNAL(signalAlbums(const QList<GAlbum>&)), |
|---|
| 351 | this, SLOT(slotAlbums(const QList<GAlbum>&))); |
|---|
| 352 | |
|---|
| 353 | connect(m_talker, SIGNAL(signalPhotos(const QList<GPhoto>&)), |
|---|
| 354 | this, SLOT(slotPhotos(const QList<GPhoto>&))); |
|---|
| 355 | |
|---|
| 356 | connect(m_talker, SIGNAL(signalAddPhotoSucceeded()), |
|---|
| 357 | this, SLOT(slotAddPhotoSucceeded())); |
|---|
| 358 | |
|---|
| 359 | connect(m_talker, SIGNAL(signalAddPhotoFailed(const QString&)), |
|---|
| 360 | this, SLOT(slotAddPhotoFailed(const QString&))); |
|---|
| 361 | } |
|---|
| 362 | |
|---|
| 363 | void PiwigoWindow::slotProcessUrl(const QString& url) |
|---|
| 364 | { |
|---|
| 365 | KToolInvocation::self()->invokeBrowser(url); |
|---|
| 366 | } |
|---|
| 367 | |
|---|
| 368 | void PiwigoWindow::readSettings() |
|---|
| 369 | { |
|---|
| 370 | // read Config |
|---|
| 371 | KConfig config("kipirc"); |
|---|
| 372 | KConfigGroup group = config.group("PiwigoSync Galleries"); |
|---|
| 373 | |
|---|
| 374 | if (group.readEntry("Resize", false)) { |
|---|
| 375 | d->resizeCheckBox->setChecked(true); |
|---|
| 376 | d->dimensionSpinBox->setEnabled(true); |
|---|
| 377 | d->dimensionSpinBox->setValue(group.readEntry("Maximum Width", 600)); |
|---|
| 378 | } else { |
|---|
| 379 | d->resizeCheckBox->setChecked(false); |
|---|
| 380 | d->dimensionSpinBox->setEnabled(false); |
|---|
| 381 | } |
|---|
| 382 | |
|---|
| 383 | if (group.readEntry("Set title", true)) |
|---|
| 384 | d->captTitleCheckBox->setChecked(true); |
|---|
| 385 | else |
|---|
| 386 | d->captTitleCheckBox->setChecked(false); |
|---|
| 387 | |
|---|
| 388 | if (group.readEntry("Set description", false)) |
|---|
| 389 | d->captDescrCheckBox->setChecked(true); |
|---|
| 390 | else |
|---|
| 391 | d->captDescrCheckBox->setChecked(false); |
|---|
| 392 | |
|---|
| 393 | } |
|---|
| 394 | |
|---|
| 395 | void PiwigoWindow::slotHelp() |
|---|
| 396 | { |
|---|
| 397 | KToolInvocation::invokeHelp("piwigoexport", "kipi-plugins"); |
|---|
| 398 | } |
|---|
| 399 | |
|---|
| 400 | void PiwigoWindow::slotDoLogin() |
|---|
| 401 | { |
|---|
| 402 | KUrl url(mpPiwigo->url()); |
|---|
| 403 | if (url.protocol().isEmpty()) { |
|---|
| 404 | url.setProtocol("http"); |
|---|
| 405 | url.setHost(mpPiwigo->url()); |
|---|
| 406 | } |
|---|
| 407 | |
|---|
| 408 | if (!url.url().endsWith(QLatin1String(".php"))) { |
|---|
| 409 | url.addPath("ws.php"); |
|---|
| 410 | } |
|---|
| 411 | |
|---|
| 412 | // If we've done something clever, save it back to the piwigo. |
|---|
| 413 | if (mpPiwigo->url() != url.url()) { |
|---|
| 414 | mpPiwigo->setUrl(url.url()); |
|---|
| 415 | mpPiwigo->save(); |
|---|
| 416 | } |
|---|
| 417 | |
|---|
| 418 | m_talker->login(url.url(), mpPiwigo->username(), mpPiwigo->password()); |
|---|
| 419 | } |
|---|
| 420 | |
|---|
| 421 | void PiwigoWindow::slotLoginFailed(const QString& msg) |
|---|
| 422 | { |
|---|
| 423 | if (KMessageBox::warningYesNo(this, |
|---|
| 424 | i18n("Failed to login into remote piwigo. ") |
|---|
| 425 | + msg |
|---|
| 426 | + i18n("\nDo you want to check your settings and try again?")) |
|---|
| 427 | != KMessageBox::Yes) { |
|---|
| 428 | close(); |
|---|
| 429 | return; |
|---|
| 430 | } |
|---|
| 431 | |
|---|
| 432 | QPointer<PiwigoEdit> configDlg = new PiwigoEdit(kapp->activeWindow(), mpPiwigo, i18n("Edit Piwigo Data") ); |
|---|
| 433 | if ( configDlg->exec() != QDialog::Accepted ) { |
|---|
| 434 | delete configDlg; |
|---|
| 435 | return; |
|---|
| 436 | } |
|---|
| 437 | slotDoLogin(); |
|---|
| 438 | delete configDlg; |
|---|
| 439 | } |
|---|
| 440 | |
|---|
| 441 | void PiwigoWindow::slotBusy(bool val) |
|---|
| 442 | { |
|---|
| 443 | if (val) { |
|---|
| 444 | setCursor(Qt::WaitCursor); |
|---|
| 445 | d->newAlbumBtn->setEnabled(false); |
|---|
| 446 | d->addPhotoBtn->setEnabled(false); |
|---|
| 447 | } else { |
|---|
| 448 | setCursor(Qt::ArrowCursor); |
|---|
| 449 | bool loggedIn = m_talker->loggedIn(); |
|---|
| 450 | // TODO Enable the button to implement the feature |
|---|
| 451 | //d->newAlbumBtn->setEnabled(loggedIn); |
|---|
| 452 | d->addPhotoBtn->setEnabled(loggedIn && d->albumView->currentItem()); |
|---|
| 453 | } |
|---|
| 454 | } |
|---|
| 455 | |
|---|
| 456 | void PiwigoWindow::slotError(const QString& msg) |
|---|
| 457 | { |
|---|
| 458 | m_progressDlg->hide(); |
|---|
| 459 | KMessageBox::error(this, msg); |
|---|
| 460 | } |
|---|
| 461 | |
|---|
| 462 | void PiwigoWindow::slotAlbums(const QList<GAlbum>& albumList) |
|---|
| 463 | { |
|---|
| 464 | d->albumDict.clear(); |
|---|
| 465 | d->albumView->clear(); |
|---|
| 466 | |
|---|
| 467 | // album work list |
|---|
| 468 | QList<GAlbum> workList(albumList); |
|---|
| 469 | QList<QTreeWidgetItem *> parentItemList; |
|---|
| 470 | |
|---|
| 471 | // fill QTreeWidget |
|---|
| 472 | while ( !workList.isEmpty() ) { |
|---|
| 473 | // the album to work on |
|---|
| 474 | GAlbum album = workList.takeFirst(); |
|---|
| 475 | |
|---|
| 476 | int parentRefNum = album.parent_ref_num; |
|---|
| 477 | if ( parentRefNum == -1 ) { |
|---|
| 478 | QTreeWidgetItem *item = new QTreeWidgetItem(); |
|---|
| 479 | item->setText(0, cleanName(album.name) ); |
|---|
| 480 | item->setIcon(0, KIcon("inode-directory") ); |
|---|
| 481 | item->setData(1, Qt::UserRole, QVariant(album.ref_num) ); |
|---|
| 482 | item->setText(2, i18n("Album") ); |
|---|
| 483 | |
|---|
| 484 | kDebug() << "Top : " << album.name << " " << album.ref_num << "\n"; |
|---|
| 485 | |
|---|
| 486 | d->albumView->addTopLevelItem(item); |
|---|
| 487 | d->albumDict.insert(album.name, album); |
|---|
| 488 | parentItemList << item; |
|---|
| 489 | } else { |
|---|
| 490 | QTreeWidgetItem *parentItem = 0; |
|---|
| 491 | bool found = false; |
|---|
| 492 | int i = 0; |
|---|
| 493 | |
|---|
| 494 | kDebug() << "Parent : " << parentRefNum << "\n"; |
|---|
| 495 | |
|---|
| 496 | while ( !found && i < parentItemList.size() ) { |
|---|
| 497 | parentItem = parentItemList.at(i); |
|---|
| 498 | |
|---|
| 499 | kDebug() << "User : " << parentItem->data(1, Qt::UserRole).toInt() << "\n"; |
|---|
| 500 | |
|---|
| 501 | if (parentItem && (parentItem->data(1, Qt::UserRole).toInt() == parentRefNum)) { |
|---|
| 502 | QTreeWidgetItem *item = new QTreeWidgetItem(parentItem); |
|---|
| 503 | item->setText(0, cleanName(album.name) ); |
|---|
| 504 | item->setIcon(0, KIcon("inode-directory") ); |
|---|
| 505 | item->setData(1, Qt::UserRole, album.ref_num ); |
|---|
| 506 | item->setText(2, i18n("Album") ); |
|---|
| 507 | |
|---|
| 508 | kDebug() << "Child : " << album.name << " " << album.ref_num << "\n"; |
|---|
| 509 | |
|---|
| 510 | parentItem->addChild(item); |
|---|
| 511 | d->albumDict.insert(album.name, album); |
|---|
| 512 | parentItemList << item; |
|---|
| 513 | found = true; |
|---|
| 514 | } |
|---|
| 515 | i++; |
|---|
| 516 | } |
|---|
| 517 | |
|---|
| 518 | /*if (!found && i == parentItemList.size() ) |
|---|
| 519 | { |
|---|
| 520 | workList.append(album); |
|---|
| 521 | }*/ |
|---|
| 522 | } |
|---|
| 523 | } |
|---|
| 524 | } |
|---|
| 525 | |
|---|
| 526 | // FIXME: avoid duplications |
|---|
| 527 | void PiwigoWindow::slotPhotos(const QList<GPhoto>& photoList) |
|---|
| 528 | { |
|---|
| 529 | QTreeWidgetItem* parentItem = d->albumView->currentItem(); |
|---|
| 530 | |
|---|
| 531 | typedef QList<GPhoto> GPhotoList; |
|---|
| 532 | GPhotoList::const_iterator iterator; |
|---|
| 533 | for (iterator = photoList.begin(); iterator != photoList.end(); ++iterator) { |
|---|
| 534 | QString plain = (*iterator).caption; |
|---|
| 535 | QTreeWidgetItem *item = new QTreeWidgetItem(parentItem); |
|---|
| 536 | item->setText(0, cleanName(plain) ); |
|---|
| 537 | item->setIcon(0, KIcon("image-x-generic") ); |
|---|
| 538 | item->setText(1, (*iterator).name); |
|---|
| 539 | item->setText(2, i18n("Image") ); |
|---|
| 540 | } |
|---|
| 541 | } |
|---|
| 542 | |
|---|
| 543 | void PiwigoWindow::slotAlbumSelected() |
|---|
| 544 | { |
|---|
| 545 | QTreeWidgetItem* item = d->albumView->currentItem(); |
|---|
| 546 | |
|---|
| 547 | kDebug() << "slotAlbumSelected\n"; |
|---|
| 548 | |
|---|
| 549 | // stop loading if user clicked an image |
|---|
| 550 | if ( item->text(2) == i18n("Image") ) |
|---|
| 551 | return; |
|---|
| 552 | |
|---|
| 553 | kDebug() << "Album\n"; |
|---|
| 554 | |
|---|
| 555 | if (!item) { |
|---|
| 556 | d->addPhotoBtn->setEnabled(false); |
|---|
| 557 | } else { |
|---|
| 558 | kDebug() << "Album selected\n"; |
|---|
| 559 | |
|---|
| 560 | int albumId = item->data(1, Qt::UserRole).toInt(); |
|---|
| 561 | kDebug() << albumId << "\n"; |
|---|
| 562 | if (m_talker->loggedIn() && albumId ) { |
|---|
| 563 | d->addPhotoBtn->setEnabled(true); |
|---|
| 564 | //m_talker->listPhotos(albumName); |
|---|
| 565 | } else { |
|---|
| 566 | d->addPhotoBtn->setEnabled(false); |
|---|
| 567 | } |
|---|
| 568 | } |
|---|
| 569 | } |
|---|
| 570 | |
|---|
| 571 | void PiwigoWindow::slotNewAlbum() |
|---|
| 572 | { |
|---|
| 573 | QPointer<AlbumDlg> dlg = new AlbumDlg(d->widget); |
|---|
| 574 | dlg->titleEdit->setFocus(); |
|---|
| 575 | if ( dlg->exec() != QDialog::Accepted ) { |
|---|
| 576 | delete dlg; |
|---|
| 577 | return; |
|---|
| 578 | } |
|---|
| 579 | |
|---|
| 580 | QString name = dlg->nameEdit->text(); |
|---|
| 581 | QString title = dlg->titleEdit->text(); |
|---|
| 582 | QString caption = dlg->captionEdit->text(); |
|---|
| 583 | |
|---|
| 584 | delete dlg; |
|---|
| 585 | |
|---|
| 586 | // check for prohibited chars in the album name |
|---|
| 587 | // \ / * ? " ' & < > | . + # ( ) or spaces |
|---|
| 588 | // TODO: Change this to a QRegExp check. |
|---|
| 589 | QChar ch; |
|---|
| 590 | bool clean = true; |
|---|
| 591 | |
|---|
| 592 | for (int i = 0; i < name.length(); ++i) { |
|---|
| 593 | ch = name[i]; |
|---|
| 594 | if (ch == '\\') { |
|---|
| 595 | clean = false; |
|---|
| 596 | break; |
|---|
| 597 | } else if (ch == '/') { |
|---|
| 598 | clean = false; |
|---|
| 599 | break; |
|---|
| 600 | } else if (ch == '*') { |
|---|
| 601 | clean = false; |
|---|
| 602 | break; |
|---|
| 603 | } else if (ch == '?') { |
|---|
| 604 | clean = false; |
|---|
| 605 | break; |
|---|
| 606 | } else if (ch == '"') { |
|---|
| 607 | clean = false; |
|---|
| 608 | break; |
|---|
| 609 | } else if (ch == '\'') { |
|---|
| 610 | clean = false; |
|---|
| 611 | break; |
|---|
| 612 | } else if (ch == '&') { |
|---|
| 613 | clean = false; |
|---|
| 614 | break; |
|---|
| 615 | } else if (ch == '<') { |
|---|
| 616 | clean = false; |
|---|
| 617 | break; |
|---|
| 618 | } else if (ch == '>') { |
|---|
| 619 | clean = false; |
|---|
| 620 | break; |
|---|
| 621 | } else if (ch == '|') { |
|---|
| 622 | clean = false; |
|---|
| 623 | break; |
|---|
| 624 | } else if (ch == '.') { |
|---|
| 625 | clean = false; |
|---|
| 626 | break; |
|---|
| 627 | } else if (ch == '+') { |
|---|
| 628 | clean = false; |
|---|
| 629 | break; |
|---|
| 630 | } else if (ch == '#') { |
|---|
| 631 | clean = false; |
|---|
| 632 | break; |
|---|
| 633 | } else if (ch == '(') { |
|---|
| 634 | clean = false; |
|---|
| 635 | break; |
|---|
| 636 | } else if (ch == ')') { |
|---|
| 637 | clean = false; |
|---|
| 638 | break; |
|---|
| 639 | } |
|---|
| 640 | /* |
|---|
| 641 | else if (ch == ' ') |
|---|
| 642 | { |
|---|
| 643 | clean = false; |
|---|
| 644 | break; |
|---|
| 645 | } |
|---|
| 646 | */ |
|---|
| 647 | } |
|---|
| 648 | |
|---|
| 649 | if (!clean) { |
|---|
| 650 | KMessageBox::error(this, i18n("Sorry, these characters are not allowed in album name: \\ / * ? \" \' & < > | . + # ( ) or spaces")); |
|---|
| 651 | return; |
|---|
| 652 | } |
|---|
| 653 | |
|---|
| 654 | QString parentAlbumName; |
|---|
| 655 | |
|---|
| 656 | QTreeWidgetItem* item = d->albumView->currentItem(); |
|---|
| 657 | int column = d->albumView->currentColumn(); |
|---|
| 658 | if (item) { |
|---|
| 659 | const GAlbum& album = d->albumDict.value( item->text(column) ); |
|---|
| 660 | parentAlbumName = album.name; |
|---|
| 661 | m_talker->createAlbum( parentAlbumName, name, title, caption); |
|---|
| 662 | } else { |
|---|
| 663 | m_talker->createAlbum( firstAlbumName, name, title, caption ); |
|---|
| 664 | } |
|---|
| 665 | } |
|---|
| 666 | |
|---|
| 667 | void PiwigoWindow::slotAddPhoto() |
|---|
| 668 | { |
|---|
| 669 | #if 0 |
|---|
| 670 | QTreeWidgetItem* item = d->albumView->currentItem(); |
|---|
| 671 | int column = d->albumView->currentColumn(); |
|---|
| 672 | if (!item) |
|---|
| 673 | return; // NO album selected: FIXME: do something |
|---|
| 674 | |
|---|
| 675 | // albumName |
|---|
| 676 | QString albumTitle = item->text(column); |
|---|
| 677 | if (!d->albumDict.contains(albumTitle)) |
|---|
| 678 | return; // NO album name found: FIXME: do something |
|---|
| 679 | |
|---|
| 680 | // photoPath |
|---|
| 681 | KUrl::List urls = KIPIPlugins::ImageDialog::getImageUrls(this, m_interface); |
|---|
| 682 | if (urls.isEmpty()) |
|---|
| 683 | return; // NO photo selected: FIXME: do something |
|---|
| 684 | |
|---|
| 685 | for (KUrl::List::iterator it = urls.begin(); it != urls.end(); ++it) { |
|---|
| 686 | mpUploadList->append( (*it).path() ); |
|---|
| 687 | } |
|---|
| 688 | |
|---|
| 689 | m_uploadTotal = mpUploadList->count(); |
|---|
| 690 | m_progressDlg->reset(); |
|---|
| 691 | m_progressDlg->setMaximum(m_uploadTotal); |
|---|
| 692 | m_uploadCount = 0; |
|---|
| 693 | slotAddPhotoNext(); |
|---|
| 694 | #endif |
|---|
| 695 | KUrl::List *urls = new KUrl::List(m_interface->currentSelection().images()); |
|---|
| 696 | |
|---|
| 697 | if (urls == NULL || urls->isEmpty()) { |
|---|
| 698 | KMessageBox::error(this, i18n("Nothing to upload - please select photos to upload.")); |
|---|
| 699 | return; |
|---|
| 700 | } |
|---|
| 701 | |
|---|
| 702 | for (KUrl::List::iterator it = urls->begin(); it != urls->end(); ++it) { |
|---|
| 703 | mpUploadList->append( (*it).path() ); |
|---|
| 704 | } |
|---|
| 705 | |
|---|
| 706 | m_uploadTotal = mpUploadList->count(); |
|---|
| 707 | m_progressDlg->reset(); |
|---|
| 708 | m_progressDlg->setMaximum(m_uploadTotal); |
|---|
| 709 | m_uploadCount = 0; |
|---|
| 710 | slotAddPhotoNext(); |
|---|
| 711 | } |
|---|
| 712 | |
|---|
| 713 | void PiwigoWindow::slotAddPhotoNext() |
|---|
| 714 | { |
|---|
| 715 | if ( mpUploadList->isEmpty() ) { |
|---|
| 716 | m_progressDlg->reset(); |
|---|
| 717 | m_progressDlg->hide(); |
|---|
| 718 | //slotAlbumSelected(); // ? |
|---|
| 719 | return; |
|---|
| 720 | } |
|---|
| 721 | |
|---|
| 722 | QTreeWidgetItem* item = d->albumView->currentItem(); |
|---|
| 723 | int column = d->albumView->currentColumn(); |
|---|
| 724 | QString albumTitle = item->text(column); |
|---|
| 725 | const GAlbum& album = d->albumDict.value(albumTitle); |
|---|
| 726 | QString photoPath = mpUploadList->takeFirst(); |
|---|
| 727 | QString photoName = QFileInfo(photoPath).baseName(); |
|---|
| 728 | bool res = m_talker->addPhoto(album.ref_num, photoPath, photoName, |
|---|
| 729 | d->captTitleCheckBox->isChecked(), |
|---|
| 730 | d->captDescrCheckBox->isChecked(), |
|---|
| 731 | d->resizeCheckBox->isChecked(), |
|---|
| 732 | d->dimensionSpinBox->value(), |
|---|
| 733 | d->thumbDimensionSpinBox->value() ); |
|---|
| 734 | |
|---|
| 735 | if (!res) { |
|---|
| 736 | slotAddPhotoFailed( "" ); |
|---|
| 737 | return; |
|---|
| 738 | } |
|---|
| 739 | |
|---|
| 740 | m_progressDlg->setLabelText( i18n("Uploading file ") + KUrl(photoPath).fileName() ); |
|---|
| 741 | |
|---|
| 742 | if (m_progressDlg->isHidden()) |
|---|
| 743 | m_progressDlg->show(); |
|---|
| 744 | } |
|---|
| 745 | |
|---|
| 746 | void PiwigoWindow::slotAddPhotoSucceeded() |
|---|
| 747 | { |
|---|
| 748 | m_uploadCount++; |
|---|
| 749 | m_progressDlg->setValue(m_uploadCount); |
|---|
| 750 | slotAddPhotoNext(); |
|---|
| 751 | } |
|---|
| 752 | |
|---|
| 753 | void PiwigoWindow::slotAddPhotoFailed(const QString& msg) |
|---|
| 754 | { |
|---|
| 755 | m_progressDlg->reset(); |
|---|
| 756 | m_progressDlg->hide(); |
|---|
| 757 | |
|---|
| 758 | if (KMessageBox::warningContinueCancel(this, |
|---|
| 759 | i18n("Failed to upload photo into " |
|---|
| 760 | "remote piwigo. ") |
|---|
| 761 | + msg |
|---|
| 762 | + i18n("\nDo you want to continue?")) |
|---|
| 763 | != KMessageBox::Continue) { |
|---|
| 764 | } else { |
|---|
| 765 | slotAddPhotoNext(); |
|---|
| 766 | } |
|---|
| 767 | } |
|---|
| 768 | |
|---|
| 769 | void PiwigoWindow::slotAddPhotoCancel() |
|---|
| 770 | { |
|---|
| 771 | m_progressDlg->reset(); |
|---|
| 772 | m_progressDlg->hide(); |
|---|
| 773 | m_talker->cancel(); |
|---|
| 774 | } |
|---|
| 775 | |
|---|
| 776 | void PiwigoWindow::slotEnableSpinBox(int n) |
|---|
| 777 | { |
|---|
| 778 | bool b; |
|---|
| 779 | switch (n) { |
|---|
| 780 | case 0: |
|---|
| 781 | b = false; |
|---|
| 782 | break; |
|---|
| 783 | case 1: |
|---|
| 784 | case 2: |
|---|
| 785 | b = true; |
|---|
| 786 | break; |
|---|
| 787 | default: |
|---|
| 788 | b = false; |
|---|
| 789 | } |
|---|
| 790 | d->dimensionSpinBox->setEnabled(b); |
|---|
| 791 | } |
|---|
| 792 | |
|---|
| 793 | void PiwigoWindow::slotSettings() |
|---|
| 794 | { |
|---|
| 795 | // TODO: reload albumlist if OK slot used. |
|---|
| 796 | QPointer<PiwigoEdit> dlg = new PiwigoEdit(kapp->activeWindow(), mpPiwigo, i18n("Edit Piwigo Data") ); |
|---|
| 797 | if ( dlg->exec() == QDialog::Accepted ) { |
|---|
| 798 | slotDoLogin(); |
|---|
| 799 | } |
|---|
| 800 | delete dlg; |
|---|
| 801 | } |
|---|
| 802 | |
|---|
| 803 | |
|---|
| 804 | QString PiwigoWindow::cleanName(const QString& str) |
|---|
| 805 | { |
|---|
| 806 | QString plain = str; |
|---|
| 807 | plain.replace("<", "<"); |
|---|
| 808 | plain.replace(">", ">"); |
|---|
| 809 | plain.replace(""", "\""); |
|---|
| 810 | plain.replace("&", "&"); |
|---|
| 811 | |
|---|
| 812 | return plain; |
|---|
| 813 | } |
|---|
| 814 | |
|---|
| 815 | } // namespace KIPIPiwigoExportPlugin |
|---|