diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-01-19 18:22:05 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-01-19 18:22:05 +0000 |
commit | 57e10fedbcb8c3e8c6590ff0935dbf017ce5587f (patch) | |
tree | 3000a7649ca4e40e43f9e7feed963236a0b0f56b /kipi-plugins/sendimages | |
download | kipi-plugins-57e10fedbcb8c3e8c6590ff0935dbf017ce5587f.tar.gz kipi-plugins-57e10fedbcb8c3e8c6590ff0935dbf017ce5587f.zip |
Import abandoned KDE3 version of kipi plugins
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/libraries/kipi-plugins@1077221 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kipi-plugins/sendimages')
-rw-r--r-- | kipi-plugins/sendimages/Makefile.am | 29 | ||||
-rw-r--r-- | kipi-plugins/sendimages/actions.h | 62 | ||||
-rw-r--r-- | kipi-plugins/sendimages/kipiplugin_sendimages.desktop | 57 | ||||
-rw-r--r-- | kipi-plugins/sendimages/listimageserrordialog.cpp | 92 | ||||
-rw-r--r-- | kipi-plugins/sendimages/listimageserrordialog.h | 55 | ||||
-rw-r--r-- | kipi-plugins/sendimages/plugin_sendimages.cpp | 292 | ||||
-rw-r--r-- | kipi-plugins/sendimages/plugin_sendimages.h | 74 | ||||
-rw-r--r-- | kipi-plugins/sendimages/sendimages.cpp | 944 | ||||
-rw-r--r-- | kipi-plugins/sendimages/sendimages.h | 190 | ||||
-rw-r--r-- | kipi-plugins/sendimages/sendimagesdialog.cpp | 689 | ||||
-rw-r--r-- | kipi-plugins/sendimages/sendimagesdialog.h | 173 |
11 files changed, 2657 insertions, 0 deletions
diff --git a/kipi-plugins/sendimages/Makefile.am b/kipi-plugins/sendimages/Makefile.am new file mode 100644 index 0000000..77c576c --- /dev/null +++ b/kipi-plugins/sendimages/Makefile.am @@ -0,0 +1,29 @@ +INCLUDES = $(LIBKEXIV2_CFLAGS) $(LIBKDCRAW_CFLAGS) $(KIPI_PLUGINS_COMMON_INCLUDE) \ + $(LIBKIPI_CFLAGS) $(all_includes) + +METASOURCES = AUTO + +# Install this plugin in the KDE modules directory +kde_module_LTLIBRARIES = kipiplugin_sendimages.la +kipiplugin_sendimages_la_DEPENDENCIES = $(LIBKIPI_LIBS_DEP) $(LIBKEXIV2_LIBS_DEP) $(LIBKDCRAW_LIBS_DEP) + +# Srcs for the plugin +kipiplugin_sendimages_la_SOURCES = plugin_sendimages.cpp sendimagesdialog.cpp \ + listimageserrordialog.cpp sendimages.cpp + +# Libs needed by the plugin +kipiplugin_sendimages_la_LIBADD = $(LIBKEXIV2_LIBS) $(LIBKIPI_LIBS) $(LIB_KIO) $(LIBKDCRAW_LIBS) \ + $(LIB_KDEUI) $(LIB_KDECORE) $(LIB_QT) + +# LD flags for the plugin +kipiplugin_sendimages_la_LDFLAGS = $(KIPI_PLUGINS_COMMON_LDFLAGS) \ + -module $(KDE_PLUGIN) $(all_libraries) -lkipiplugins + +# Install the desktop file needed to detect the plugin +kde_services_DATA = kipiplugin_sendimages.desktop + +# i18n translation messages +messages: rc.cpp + $(XGETTEXT) *.cpp *.h -o $(podir)/kipiplugin_sendimages.pot + + diff --git a/kipi-plugins/sendimages/actions.h b/kipi-plugins/sendimages/actions.h new file mode 100644 index 0000000..6946e19 --- /dev/null +++ b/kipi-plugins/sendimages/actions.h @@ -0,0 +1,62 @@ +/* ============================================================ + * + * This file is a part of kipi-plugins project + * http://www.kipi-plugins.org + * + * Date : 2004-02-25 + * Description : a kipi plugin to e-mailing images + * + * Copyright (C) 2004-2007 by 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, 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. + * + * ============================================================ */ + +#ifndef ACTIONS_H +#define ACTIONS_H + +namespace KIPISendimagesPlugin +{ + +enum Action +{ + Initialize = 0, + Progress, + Error, + ResizeImages +}; + +class EventData +{ + +public: + + EventData() + { + starting = false; + success = false; + } + + bool starting; + bool success; + + int total; + + QString fileName; + QString albumName; + QString errString; + + Action action; +}; + +} // NameSpace KIPISendimagesPlugin + +#endif // ACTIONS_H diff --git a/kipi-plugins/sendimages/kipiplugin_sendimages.desktop b/kipi-plugins/sendimages/kipiplugin_sendimages.desktop new file mode 100644 index 0000000..8b943a9 --- /dev/null +++ b/kipi-plugins/sendimages/kipiplugin_sendimages.desktop @@ -0,0 +1,57 @@ +[Desktop Entry] +Encoding=UTF-8 +Name=SendImages +Name[br]=Kas ar skeudennoù +Name[ca]=Enviament d'imatges +Name[cs]=Odeslání obrázku +Name[da]=Send billeder +Name[de]=Bilder senden +Name[el]=ΑποστολήΕικόνων +Name[es]=Enviar imágenes +Name[et]=Piltide saatmine +Name[fi]=Sähköpostilähetys +Name[gl]=Envio de Imaxes +Name[it]=InviaImmagini +Name[nds]=Biller sennen +Name[nl]=AfbeeldingenVerzenden +Name[pl]=Wyślij zdjęcia +Name[pt]=Envio de Imagens +Name[sr]=Шаљи слике +Name[sr@Latn]=Šalji slike +Name[sv]=Skicka bilder +Name[tg]=ФиристоданиТасвирҳо +Name[tr]=ResimGönder +Name[xx]=xxSendImagesxx +Name[zh_CN]=发送图像 +Comment=KIPI EMail Images Plugin +Comment[ca]=Connector del KIPI per enviar imatges per correu-e +Comment[cs]=KIPI modul odeslání obrázku +Comment[da]=KIPI-plugin: Send billeder med e-mail +Comment[de]=Ein KIPI-Modul zum Versenden von Bildern per E-Mail +Comment[el]=Πρόσθετο του KIPI για αποστολή ηλεκτρονικού μηνύματος εικόνων +Comment[es]=Complemento de KIPI para enviar imágenes por correo electrónico +Comment[et]=KIPI piltide e-postiga saatmise plugin +Comment[fi]=Kipi-liitännäinen sähköpostilähetyksiä varten +Comment[fr]=Module externe KIPI pour envoyer des images par courrier électronique +Comment[gl]=Plugin de KIPI para Enviar Imaxes por EMail +Comment[it]=Plugin di invio immagini di KIPI +Comment[ja]=Kipi 画像メール送信プラグイン +Comment[nds]=KIPI-Moduul för't Sennen vun Biller mit Nettpost +Comment[nl]=KIPI-plugin voor het verzenden van afbeeldingen via e-mail +Comment[pa]=KIPI ਈ-ਮੇਲ ਚਿੱਤਰ ਪਲੱਗਇਨ +Comment[pl]=Wtyczka KIPI - Wysyłanie zdjęć e-mailem +Comment[pt]='Plugin' do KIPI de Envio de Imagens por E-Mail +Comment[pt_BR]=Plugin para Email de Imagens do KIPI +Comment[sr]=KIPI прикључак за слање слика е-поштом +Comment[sr@Latn]=KIPI priključak za slanje slika e-poštom +Comment[sv]=KIPI-insticksprogram: Skicka bilder med e-post +Comment[tg]=Модули KIPI барои тасвирҳои почтаи электронӣ +Comment[tr]=KIPI Resim Gönderme Eklentisi +Comment[xx]=xxKIPI EMail Images Pluginxx +Comment[zh_CN]=KIPI 电邮图像插件 +Icon= +ServiceTypes=KIPI/Plugin +Type=Service +X-KDE-Library=kipiplugin_sendimages +author=Gilles Caulier, caulier dot gilles at gmail dot com +X-KIPI-MergeMenu=true diff --git a/kipi-plugins/sendimages/listimageserrordialog.cpp b/kipi-plugins/sendimages/listimageserrordialog.cpp new file mode 100644 index 0000000..307c7fa --- /dev/null +++ b/kipi-plugins/sendimages/listimageserrordialog.cpp @@ -0,0 +1,92 @@ +/* ============================================================ + * + * This file is a part of kipi-plugins project + * http://www.kipi-plugins.org + * + * Date : 2003-10-01 + * Description : a kipi plugin to e-mailing images + * + * Copyright (C) 2003-2007 by 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, 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. + * + * ============================================================ */ + +// Qt includes + +#include <qpushbutton.h> +#include <qlayout.h> +#include <qstringlist.h> +#include <qstring.h> +#include <qlabel.h> +#include <qfileinfo.h> +#include <qframe.h> + +// KDElib includes + +#include <klocale.h> +#include <klistview.h> +#include <kurl.h> +#include <kstandarddirs.h> + +// Local includes. + +#include "listimageserrordialog.h" +#include "listimageserrordialog.moc" + +namespace KIPISendimagesPlugin +{ + +listImagesErrorDialog::listImagesErrorDialog(QWidget* parent, QString Caption, + const QString &Mess1, const QString &Mess2, + KURL::List ListOfiles) + : KDialogBase( Caption, Yes|No|Cancel, Yes, Cancel, parent, + "listImagesErrorDialog", true, false ) +{ + QWidget* box = new QWidget( this ); + setMainWidget(box); + QVBoxLayout* ml = new QVBoxLayout(box); + + //--------------------------------------------- + + QHBoxLayout* h1 = new QHBoxLayout( ml ); + QVBoxLayout* v1 = new QVBoxLayout( h1 ); + h1->addSpacing( 5 ); + QGridLayout* g1 = new QGridLayout( v1, 1, 3 ); + + QLabel *labelMess1 = new QLabel ( Mess1, box); + m_listFiles = new KListView( box ); + m_listFiles->addColumn(i18n("Image File Name")); + m_listFiles->addColumn(i18n("From Album")); + m_listFiles->setSorting(1); + m_listFiles->setItemMargin(3); + m_listFiles->setResizeMode(QListView::LastColumn); + QLabel *labelMess2 = new QLabel ( Mess2, box); + + g1->addWidget (labelMess1, 1, 1); + g1->addWidget (m_listFiles, 2, 1); + g1->addWidget (labelMess2, 3, 1); + + for ( KURL::List::Iterator it = ListOfiles.begin() ; it != ListOfiles.end() ; ++it ) + { + new KListViewItem( m_listFiles, + (*it).fileName(), + (*it).directory().section('/', -1) ); + } + + resize( 500, 400 ); +} + +listImagesErrorDialog::~listImagesErrorDialog() +{ +} + +} // NameSpace KIPISendimagesPlugin diff --git a/kipi-plugins/sendimages/listimageserrordialog.h b/kipi-plugins/sendimages/listimageserrordialog.h new file mode 100644 index 0000000..494b4d4 --- /dev/null +++ b/kipi-plugins/sendimages/listimageserrordialog.h @@ -0,0 +1,55 @@ +/* ============================================================ + * + * This file is a part of kipi-plugins project + * http://www.kipi-plugins.org + * + * Date : 2003-10-01 + * Description : a kipi plugin to e-mailing images + * + * Copyright (C) 2003-2007 by 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, 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. + * + * ============================================================ */ + +#ifndef LISTIMAGESERRORDIALOG_included +#define LISTIMAGESERRORDIALOG_included + +// KDElib includes + +#include <kdialogbase.h> + +class KListView; +class KURL::List; + +namespace KIPISendimagesPlugin +{ + +class listImagesErrorDialog : public KDialogBase +{ + Q_OBJECT + +public: + + listImagesErrorDialog(QWidget* parent, QString Caption, + const QString &Mess1, const QString &Mess2, + KURL::List ListOfiles); + + ~listImagesErrorDialog(); + +private: + + KListView *m_listFiles; +}; + +} // NameSpace KIPISendimagesPlugin + +#endif // LISTIMAGESERRORDIALOG_included diff --git a/kipi-plugins/sendimages/plugin_sendimages.cpp b/kipi-plugins/sendimages/plugin_sendimages.cpp new file mode 100644 index 0000000..f6441a0 --- /dev/null +++ b/kipi-plugins/sendimages/plugin_sendimages.cpp @@ -0,0 +1,292 @@ +/* ============================================================ + * + * This file is a part of kipi-plugins project + * http://www.kipi-plugins.org + * + * Date : 2003-10-01 + * Description : a kipi plugin to e-mailing images + * + * Copyright (C) 2003-2007 by 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, 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. + * + * ============================================================ */ + +// C Ansi includes + +extern "C" +{ +#include <unistd.h> +} + +// Include files for KDE + +#include <klocale.h> +#include <kapplication.h> +#include <kglobal.h> +#include <kaction.h> +#include <kgenericfactory.h> +#include <klibloader.h> +#include <kconfig.h> +#include <kdebug.h> +#include <kiconloader.h> +#include <kinstance.h> +#include <kmessagebox.h> +#include <kstandarddirs.h> +#include <ktempfile.h> +#include <kimageio.h> +#include <kdeversion.h> + +// LibKipi includes. + +#include <libkipi/batchprogressdialog.h> + +// Local includes + +#include "actions.h" +#include "sendimages.h" +#include "plugin_sendimages.h" +#include "plugin_sendimages.moc" + +typedef KGenericFactory<Plugin_SendImages> Factory; + +K_EXPORT_COMPONENT_FACTORY( kipiplugin_sendimages, + Factory("kipiplugin_sendimages")) + +// ----------------------------------------------------------- +Plugin_SendImages::Plugin_SendImages(QObject *parent, const char*, const QStringList&) + : KIPI::Plugin( Factory::instance(), parent, "SendImages") +{ + kdDebug( 51001 ) << "Plugin_SendImages plugin loaded" << endl; + +} + +void Plugin_SendImages::setup( QWidget* widget ) +{ + KIPI::Plugin::setup( widget ); + + m_action_sendimages = new KAction (i18n("Email Images..."), // Menu message. + "mail_new", // Menu icon. + 0, + this, + SLOT(slotActivate()), + actionCollection(), + "send_images"); + + addAction( m_action_sendimages ); + + KIPI::Interface* interface = dynamic_cast< KIPI::Interface* >( parent() ); + if ( !interface ) + { + kdError( 51000 ) << "Kipi interface is null!" << endl; + return; + } + + KIPI::ImageCollection selection = interface->currentSelection(); + m_action_sendimages->setEnabled( selection.isValid() && + !selection.images().isEmpty() ); + + connect( interface, SIGNAL(selectionChanged(bool)), + m_action_sendimages, SLOT(setEnabled(bool))); +} + +Plugin_SendImages::~Plugin_SendImages() +{ +} + +void Plugin_SendImages::slotActivate() +{ + m_progressDlg = 0; + + KIPI::Interface* interface = dynamic_cast<KIPI::Interface*>( parent() ); + if ( !interface ) + { + kdError( 51000 ) << "Kipi interface is null!" << endl; + return; + } + + KIPI::ImageCollection images = interface->currentSelection(); + + if ( !images.isValid() || images.images().isEmpty() ) + return; + + KStandardDirs dir; + QString Tmp = dir.saveLocation("tmp", "kipi-sendimagesplugin-" + QString::number(getpid()) + "/"); + + m_sendImagesOperation = new KIPISendimagesPlugin::SendImages( interface, Tmp, images, this ); + + m_sendImagesOperation->showDialog(); +} + +void Plugin_SendImages::slotAcceptedConfigDlg() +{ + m_sendImagesOperation->prepare(); + m_sendImagesOperation->start(); +} + +void Plugin_SendImages::slotCancel() +{ + m_sendImagesOperation->terminate(); + m_sendImagesOperation->wait(); + m_sendImagesOperation->removeTmpFiles(); +} + +void Plugin_SendImages::customEvent(QCustomEvent *event) +{ + if (!event) return; + + if (!m_progressDlg) + { + m_progressDlg = new KIPI::BatchProgressDialog(kapp->activeWindow(), i18n("Preparing images to send")); + + connect(m_progressDlg, SIGNAL(cancelClicked()), + this, SLOT(slotCancel())); + + m_current = 0; + m_progressDlg->show(); + } + + KIPISendimagesPlugin::EventData *d = (KIPISendimagesPlugin::EventData*) event->data(); + + if (!d) return; + + if (d->starting) + { + QString text; + + switch (d->action) + { + case(KIPISendimagesPlugin::Initialize): + { + m_total = d->total; + text = i18n("Preparing 1 image to send....", "Preparing %n images to send....", d->total); + break; + } + + case(KIPISendimagesPlugin::ResizeImages): + { + text = i18n("Resizing '%1' from Album '%2'...") + .arg(d->fileName).arg(d->albumName); + break; + } + + case(KIPISendimagesPlugin::Progress): + { + text = i18n("Using '%1' from Album '%2' without resizing...") + .arg(d->fileName).arg(d->albumName); + break; + } + + default: + { + kdWarning( 51000 ) << "Plugin_SendImages: Unknown 'Starting' event: " << d->action << endl; + } + } + + m_progressDlg->addedAction(text, KIPI::StartingMessage); + } + else + { + QString text; + + if (!d->success) + { + switch (d->action) + { + case(KIPISendimagesPlugin::ResizeImages): + { + text = i18n("Failed to resize '%1' from Album '%2'") + .arg(d->fileName).arg(d->albumName); + break; + } + + default: + { + kdWarning( 51000 ) << "Plugin_SendImages: Unknown 'Failed' event: " << d->action << endl; + } + } + + m_progressDlg->addedAction(text, KIPI::WarningMessage); + } + else + { + switch (d->action) + { + case(KIPISendimagesPlugin::ResizeImages): + { + text = i18n("Resizing '%1' from Album '%2' completed.") + .arg(d->fileName).arg(d->albumName); + break; + } + + case(KIPISendimagesPlugin::Progress): + { + text = i18n("All preparatory operations completed."); + break; + } + + default: + { + kdWarning( 51000 ) << "Plugin_CDArchiving: Unknown 'Success' event: " << d->action << endl; + } + } + + m_progressDlg->addedAction(text, KIPI::SuccessMessage); + } + + ++m_current; + m_progressDlg->setProgress(m_current, m_total); + + if( d->action == KIPISendimagesPlugin::Progress ) + { + // If we have some errors during the resizing images process, show an error dialog. + + if ( m_sendImagesOperation->showErrors() == false ) + { + delete m_progressDlg; + return; + } + +#if KDE_VERSION >= 0x30200 + m_progressDlg->setButtonCancel( KStdGuiItem::close() ); +#else + m_progressDlg->setButtonCancelText( i18n("&Close") ); +#endif + + disconnect(m_progressDlg, SIGNAL(cancelClicked()), + this, SLOT(slotCancel())); + + // Create a text file with images comments if necessary. + + m_sendImagesOperation->makeCommentsFile(); + m_progressDlg->addedAction(i18n("Creating comments file if necessary..."), + KIPI::StartingMessage); + + // Invoke mailer agent call. + int type = m_sendImagesOperation->invokeMailAgent() ? KIPI::SuccessMessage : KIPI::ErrorMessage; + m_progressDlg->addedAction(i18n("Starting mailer agent..."), type); + + m_progressDlg->setProgress(m_total, m_total); + } + } + + kapp->processEvents(); + delete d; +} + +KIPI::Category Plugin_SendImages::category( KAction* action ) const +{ + if ( action == m_action_sendimages ) + return KIPI::IMAGESPLUGIN; + + kdWarning( 51000 ) << "Unrecognized action for plugin category identification" << endl; + return KIPI::IMAGESPLUGIN; // no warning from compiler, please +} diff --git a/kipi-plugins/sendimages/plugin_sendimages.h b/kipi-plugins/sendimages/plugin_sendimages.h new file mode 100644 index 0000000..dee11c5 --- /dev/null +++ b/kipi-plugins/sendimages/plugin_sendimages.h @@ -0,0 +1,74 @@ +/* ============================================================ + * + * This file is a part of kipi-plugins project + * http://www.kipi-plugins.org + * + * Date : 2003-10-01 + * Description : a kipi plugin to e-mailing images + * + * Copyright (C) 2003-2007 by 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, 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. + * + * ============================================================ */ + +#ifndef PLUGIN_SENDIMAGES_H +#define PLUGIN_SENDIMAGES_H + +// KIPI includes + +#include <libkipi/plugin.h> + +class QCustomEvent; + +class KAction; +class KIPISendimagesPlugin::SendImages; + +namespace KIPI +{ + class BatchProgressDialog; +} + +class Plugin_SendImages : public KIPI::Plugin +{ +Q_OBJECT + +public: + + Plugin_SendImages(QObject *parent, const char* name, const QStringList &args); + ~Plugin_SendImages(); + + virtual KIPI::Category category( KAction* action ) const; + virtual void setup( QWidget* ); + +public slots: + + void slotActivate(); + void slotCancel(); + void slotAcceptedConfigDlg(); + +private: + + void customEvent(QCustomEvent *event); + +private: + + int m_current; + int m_total; + + KAction *m_action_sendimages; + + KIPI::BatchProgressDialog *m_progressDlg; + + KIPISendimagesPlugin::SendImages *m_sendImagesOperation; +}; + +#endif // PLUGIN_SENDIMAGES_H diff --git a/kipi-plugins/sendimages/sendimages.cpp b/kipi-plugins/sendimages/sendimages.cpp new file mode 100644 index 0000000..abbdf62 --- /dev/null +++ b/kipi-plugins/sendimages/sendimages.cpp @@ -0,0 +1,944 @@ +/* ============================================================ + * + * This file is a part of kipi-plugins project + * http://www.kipi-plugins.org + * + * Date : 2004-02-25 + * Description : a kipi plugin to e-mailing images + * + * Copyright (C) 2004-2008 by Gilles Caulier <caulier dot gilles at gmail dot com> + * Copyright (C) 2006 by Tom Albers <tomalbers at kde dot nl> + * Copyright (C) 2006 by Michael Hoechstetter <michael dot hoechstetter at gmx dot de> + * + * 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. + * + * ============================================================ */ + +// Qt includes. + +#include <qfileinfo.h> +#include <qdir.h> +#include <qimage.h> +#include <qprogressdialog.h> +#include <qcombobox.h> +#include <qcheckbox.h> +#include <qtimer.h> +#include <qurl.h> +#include <qdeepcopy.h> + +// KDE includes + +#include <klocale.h> +#include <kinstance.h> +#include <kconfig.h> +#include <kapplication.h> +#include <kimageeffect.h> +#include <kprogress.h> +#include <kmessagebox.h> +#include <kstandarddirs.h> +#include <kio/job.h> +#include <kio/jobclasses.h> +#include <kio/netaccess.h> +#include <kio/global.h> +#include <kprocess.h> +#include <kimageio.h> +#include <knuminput.h> +#include <kurlrequester.h> + +// LibKExiv2 includes. + +#include <libkexiv2/kexiv2.h> + +// LibKDcraw includes. + +#include <libkdcraw/version.h> +#include <libkdcraw/kdcraw.h> + +#if KDCRAW_VERSION < 0x000106 +#include <libkdcraw/dcrawbinary.h> +#endif + +// Local includes. + +#include "sendimagesdialog.h" +#include "listimageserrordialog.h" +#include "actions.h" +#include "pluginsversion.h" +#include "sendimages.h" +#include "sendimages.moc" + +namespace KIPISendimagesPlugin +{ + +///Constructor: saves system handoff parameters in member variables +SendImages::SendImages(KIPI::Interface* interface, const QString &tmpFolder, + const KIPI::ImageCollection& imagesCollection, QObject *parent) + : QObject(parent), QThread() +{ + m_invokedBefore = false; + m_interface = interface; + m_tmp = tmpFolder; + m_collection = imagesCollection; + m_parent = parent; + m_mozillaTimer = new QTimer(this); + KImageIO::registerFormats(); + + connect(m_mozillaTimer, SIGNAL(timeout()), + this, SLOT(slotMozillaTimeout())); +} + +///Destructor +SendImages::~SendImages() +{ + delete m_sendImagesDialog; + wait(); +} + +///Invokes the User Dialog Window +void SendImages::showDialog() +{ + m_sendImagesDialog = new KIPISendimagesPlugin::SendImagesDialog(kapp->activeWindow(), + m_interface, m_collection); + m_sendImagesDialog->show(); + + connect(m_sendImagesDialog, SIGNAL(signalAccepted()), + m_parent, SLOT(slotAcceptedConfigDlg())); +} + +/** Execute the no threadable operations before the real thread. + Gets input from the user dialog and store it into member variables */ +void SendImages::prepare(void) +{ + m_filesSendList.clear(); + m_imagesResizedWithError.clear(); + m_imagesPackage.clear(); + m_images = m_sendImagesDialog->m_images2send; + m_changeProp = m_sendImagesDialog->m_changeImagesProp->isChecked(); + m_imageFormat = m_sendImagesDialog->m_imagesFormat->currentText(); + m_sizeFactor = getSize( m_sendImagesDialog->m_imagesResize->currentItem() ); + m_imageCompression = m_sendImagesDialog->m_imageCompression->value(); + + // Base64-encoding needs a lot of space. + m_attachmentlimit = m_sendImagesDialog->m_attachmentlimit->value()*770000-2000; +} + +/** List of threaded operations. + Prepares the image list. This includes resizing, copying, maintaining an image's exif, + and dropping evil characters out of filenames ;-) */ +void SendImages::run() +{ + KIPISendimagesPlugin::EventData *d; + + d = new KIPISendimagesPlugin::EventData; + d->action = KIPISendimagesPlugin::Initialize; + d->starting = true; + d->success = false; + d->total = m_images.count(); + QApplication::postEvent(m_parent, new QCustomEvent(QEvent::User, d)); + + for( KURL::List::Iterator it = m_images.begin() ; it != m_images.end() ; ++it ) + { + QString imageName = (*it).path(); + QString ItemName = imageName.section( '/', -1 ); + + d = new KIPISendimagesPlugin::EventData; + d->action = KIPISendimagesPlugin::ResizeImages; + d->fileName = (*it).fileName(); + d->albumName = (*it).directory().section('/', -1); + d->starting = true; + d->success = false; + QApplication::postEvent(m_parent, new QCustomEvent(QEvent::User, d)); + + // Prepare resized target images to send. + QString imageFileName=""; + + KIPI::ImageInfo info = m_interface->info( *it ); + + ///Generate filename of destination image + QString commentItem = info.description(); + + if ((m_sendImagesDialog->m_comment2ImageName->isChecked() == true ) && + !commentItem.isEmpty() ) + { + qDebug("commentItem: %s",commentItem.ascii()); + } + else + { + commentItem = ItemName.left(ItemName.findRev('.')); + qDebug("commentItem is empty"); + } + + //QString TempFileName = (*it).directory().section('/', -1); + QString TempFileName=(*it).path().section('/', -2,-2)+"/"+commentItem+ + +"."+(*it).path().section('.', -1,-1); + qDebug("TempFileName: %s",TempFileName.ascii()); + + + // Thunderbird does not like (). Replace them, BUG:131343 + TempFileName.replace(QChar('('), "_").replace(QChar(')'), "_"); + // and these characters are better eliminated, too ;-) + TempFileName.replace(QChar(','), "_").replace(QChar(' '), "_"); + TempFileName.replace(QChar(';'), "_").replace(QChar('%'), "_"); + TempFileName.replace(QChar('/'), "-").replace(QChar('?'), ""); + TempFileName.replace(QChar('"'), ""); + //If TempFileName already exists, add a number oder increase number + if (entry_already_exists(m_filesSendList,m_tmp + TempFileName)) + { + qDebug ("I entered"); + QString secondpart=(m_tmp+TempFileName).section(".",-1,-1); + QString firstpart= + (m_tmp+TempFileName).left((m_tmp+TempFileName).length()-secondpart.length()-1); + qDebug("Firstpart: %s \n Secondpart: %s",firstpart.ascii(), secondpart.ascii()); + //Add _integer value in the end and prove again + int int_index=2; + QString index=QString::number(int_index,10); + while (entry_already_exists(m_filesSendList,firstpart + "_"+index+"."+secondpart)) + { + int_index++; + index=QString::number(int_index,10); + qDebug("Index: %s",index.ascii()); + } + QString temp=firstpart + "_"+index+"."+secondpart; + TempFileName=temp.right(temp.length()-m_tmp.length()); + // .section("-",-2,-1); + // m_tmp=(firstpart + "_"+index+"."+secondpart).section("-",-2); + } + + if ( m_changeProp == true ) + { + // Prepare resizing images. + + //QString imageNameFormat = TempFileName.replace(QChar('.'), "_") + + // extension(m_imageFormat); + + qDebug( "Resizing %s-> '%s %s ' (%s ; %d )",imageName.ascii(), + m_tmp.ascii(),TempFileName.ascii(),m_imageFormat.ascii(),m_sizeFactor); + + // Return value for resizeImageProcess-function, in order to avoid reopening + // the image for exiv-writing. + QSize newsize; + + if ( resizeImageProcess( imageName, m_tmp, m_imageFormat, TempFileName, + m_sizeFactor, m_imageCompression, newsize) == false ) + { + // Resized images failed... + + d = new KIPISendimagesPlugin::EventData; + d->action = KIPISendimagesPlugin::ResizeImages; + d->fileName = (*it).fileName(); + d->albumName = (*it).directory().section('/', -1); + d->starting = false; + d->success = false; + QApplication::postEvent(m_parent, new QCustomEvent(QEvent::User, d)); + + m_imagesResizedWithError.append(*it); + } + else // Resized images OK... + { + // Only try to write Exif if both src and destination are JPEG files. + + if (QString(QImageIO::imageFormat(imageName)).upper() == "JPEG" && + m_imageFormat.upper() == "JPEG") + { + QString targetFile = m_tmp + TempFileName; + KExiv2Iface::KExiv2 exiv2Iface; + + if (exiv2Iface.load(imageName)) + { + exiv2Iface.setImageProgramId(QString("Kipi-plugins"), QString(kipiplugins_version)); + exiv2Iface.setImageDimensions(newsize); + exiv2Iface.save(targetFile); + } + } + else + { + qWarning( "createThumb::No Exif Data Found") ; + } + + d = new KIPISendimagesPlugin::EventData; + d->action = KIPISendimagesPlugin::ResizeImages; + d->fileName = (*it).fileName(); + d->albumName = (*it).directory().section('/', -1); + d->starting = false; + d->success = true; + QApplication::postEvent(m_parent, new QCustomEvent(QEvent::User, d)); + + m_filesSendList.append(m_tmp + TempFileName); + m_imagesPackage.append(*it); + m_imagesPackage.append(m_tmp + TempFileName); + } + } + else // No resize images operations... + { + if ( copyImageProcess( imageName, m_tmp, TempFileName) == true ) + { + d = new KIPISendimagesPlugin::EventData; + d->action = KIPISendimagesPlugin::Progress; + d->fileName = (*it).fileName(); + d->albumName = (*it).directory().section('/', -1); + d->starting = true; + d->success = false; + QApplication::postEvent(m_parent, new QCustomEvent(QEvent::User, d)); + + m_filesSendList.append(m_tmp + TempFileName); + m_imagesPackage.append(*it); + m_imagesPackage.append(m_tmp + TempFileName); + } + } + } + + d = new KIPISendimagesPlugin::EventData; + d->action = KIPISendimagesPlugin::Progress; + d->starting = false; + d->success = true; + QApplication::postEvent(m_parent, new QCustomEvent(QEvent::User, d)); +} + +bool SendImages::entry_already_exists(KURL::List filenamelist,QString entry) +{ + KURL::List::Iterator it = filenamelist.begin(); + while( it != filenamelist.end() ) + { + if ((*it)==entry) return true; + it++; + } + return false; +} + +/// Creates a text file with the images comments. +void SendImages::makeCommentsFile(void) +{ + if ( m_sendImagesDialog->m_addComments->isChecked() == true ) + { + QString ImageCommentsText; + + KURL::List::Iterator it = m_imagesPackage.begin(); + bool anyCommentsPresent = false; + + while( it != m_imagesPackage.end() ) + { + KIPI::ImageInfo info = m_interface->info( *it ); + + QString commentItem = info.description(); + ++it; + QString targetFile = (*it).filename(); + + if ( commentItem.isEmpty() ) + commentItem = i18n("no caption"); + else + anyCommentsPresent = true; + + ImageCommentsText += i18n("Caption for image \"%1\": %2\n") + .arg(targetFile).arg(commentItem); + + //Tags from the database + if (m_interface->hasFeature(KIPI::HostSupportsTags)) + { + QMap <QString, QVariant> attribs=info.attributes(); + if (attribs["tags"].asStringList().count() > 0) + { + ImageCommentsText += i18n("Tags: %2\n").arg(attribs["tags"].asStringList().join(",")); + anyCommentsPresent = true; + } + } + + ImageCommentsText += "\n"; + ++it; + } + + if ( anyCommentsPresent ) + { + QFile commentsFile( m_tmp + i18n("comments.txt") ); + QTextStream stream( &commentsFile ); + stream.setEncoding( QTextStream::UnicodeUTF8 ); + commentsFile.open( IO_WriteOnly ); + stream << ImageCommentsText << "\n"; + commentsFile.close(); + m_filesSendList.append( m_tmp + i18n("comments.txt") ); + } + } +} + +///Shows up an error dialog and the problematic images +bool SendImages::showErrors() +{ + if ( m_imagesResizedWithError.isEmpty() == false ) + { + listImagesErrorDialog *ErrorImagesDialog = new listImagesErrorDialog(kapp->activeWindow(), + i18n("Error during resize images process."), + i18n("Cannot resize the following image files:"), + i18n("Do you want them to be added as attachments " + "(without resizing)?"), + m_imagesResizedWithError); + + int ValRet = ErrorImagesDialog->exec(); + + switch (ValRet) + { + case KDialogBase::Yes : // Added source image files instead resized images... + + for ( KURL::List::Iterator it = m_imagesResizedWithError.begin(); + it != m_imagesResizedWithError.end(); ++it ) + { + m_filesSendList.append(*it); + m_imagesPackage.append(*it); + m_imagesPackage.append(*it); + } + break; + + case KDialogBase::No : // Do nothing... + break; + + case KDialogBase::Cancel : // Stop process... + removeTmpFiles(); + return false; + break; + } + } + + return true; +} + +/** Returns a list of Filenames, whose sum filesize is smaller than the quota + The returned images are deleted from the m_filesSendList */ +KURL::List SendImages::divideEmails(void) +{ + unsigned long mylistsize=0; + + KURL::List sendnow; + KURL::List filesSendList; + + for ( KURL::List::Iterator it = m_filesSendList.begin() ; it != m_filesSendList.end() ; ++it ) + { + qDebug("m_attachmentlimit: %lu ", m_attachmentlimit); + QString imageName = (*it).path(); + qDebug("Imagename: %s", imageName.ascii()); + QFile file(imageName); + qDebug("filesize: %lu", file.size()); + + if ((mylistsize + file.size()) <= m_attachmentlimit) + { + mylistsize+=file.size(); + sendnow.append(*it); + qDebug("mylistsize: %lu; attachmentlimit: %lu",mylistsize, m_attachmentlimit); + } + else + { + qDebug("file %s is out of %lu",imageName.ascii(),m_attachmentlimit); + filesSendList.append(*it); + } + } + m_filesSendList = filesSendList; + + return sendnow; +} + +/** Invokes mail agent. Depending on which mail agent to be used, we have different + proceedings. Easy for every agent except of mozilla derivates */ +bool SendImages::invokeMailAgent(void) +{ + bool agentInvoked = false; + + KURL::List filelist; + kurllistdeepcopy(m_filesSendList_copy,m_filesSendList); + + qDebug("invokeMailagent1: Number of elements in m_filesSendList=%d, and in m_filesSendList_copy=%d)",(int)m_filesSendList.size(),(int)m_filesSendList_copy.size()); + + while (!((filelist=divideEmails()).empty())) + { + qDebug("invokeMailagent2: Number of elements in m_filesSendList=%d, and in m_filesSendList_copy=%d)",(int) m_filesSendList.size(),(int)m_filesSendList_copy.size()); + qDebug("number of elements in filelist %d",(int)filelist.size()); + qDebug("number of elements in m_filelist %d", (int)m_filesSendList.size()); + if ( m_sendImagesDialog->m_mailAgentName->currentText() == "Default" ) + { + KApplication::kApplication()->invokeMailer( + QString::null, // Destination address. + QString::null, // Carbon Copy address. + QString::null, // Blind Carbon Copy address + QString::null, // Message Subject. + QString::null, // Message Body. + QString::null, // Message Body File. + filelist.toStringList()); // Images attachments (+ comments). + agentInvoked = true; + } + + // KMail mail agent call. + + if ( m_sendImagesDialog->m_mailAgentName->currentText() == "KMail" ) + { + m_mailAgentProc = new KProcess; + *m_mailAgentProc << "kmail"; + + for ( KURL::List::Iterator it = filelist.begin() ; it != filelist.end() ; ++it ) + { + *m_mailAgentProc << "--attach"; + *m_mailAgentProc << QFile::encodeName((*it).path()); + } + + if ( m_mailAgentProc->start() == false ) + KMessageBox::error(kapp->activeWindow(), + i18n("Cannot start '%1' program;\nplease " + "check your installation.") + .arg(m_sendImagesDialog->m_mailAgentName->currentText())); + else + agentInvoked = true; + } + + // Claws Mail and Sylpheed mail agent call. + + if ( m_sendImagesDialog->m_mailAgentName->currentText() == "Claws Mail" || + m_sendImagesDialog->m_mailAgentName->currentText() == "Sylpheed" || + m_sendImagesDialog->m_mailAgentName->currentText() == "Sylpheed-Claws" ) + { + m_mailAgentProc = new KProcess; + + if ( m_sendImagesDialog->m_mailAgentName->currentText() == "Claws Mail") + *m_mailAgentProc << "claws-mail"; + else if ( m_sendImagesDialog->m_mailAgentName->currentText() == "Sylpheed") + *m_mailAgentProc << "sylpheed"; + else + *m_mailAgentProc << "sylpheed-claws"; + + *m_mailAgentProc << "--compose" << "--attach"; + + for ( KURL::List::Iterator it = filelist.begin() ; it != filelist.end() ; ++it ) + *m_mailAgentProc << QFile::encodeName((*it).path()); + + if ( m_mailAgentProc->start() == false ) + KMessageBox::error(kapp->activeWindow(), + i18n("Cannot start '%1' program;\nplease " + "check your installation.") + .arg(m_sendImagesDialog->m_mailAgentName->currentText())); + else + agentInvoked = true; + } + + // Balsa mail agent call. + + if ( m_sendImagesDialog->m_mailAgentName->currentText() == "Balsa" ) + { + m_mailAgentProc = new KProcess; + *m_mailAgentProc << "balsa" << "-m" << "mailto:"; + + for ( KURL::List::Iterator it = filelist.begin() ; it != filelist.end() ; ++it ) + { + *m_mailAgentProc << "-a"; + *m_mailAgentProc << QFile::encodeName((*it).path()); + } + + if ( m_mailAgentProc->start() == false ) + KMessageBox::error(kapp->activeWindow(), + i18n("Cannot start '%1' program;\nplease " + "check your installation.") + .arg(m_sendImagesDialog->m_mailAgentName->currentText())); + else + agentInvoked = true; + } + + // Evolution mail agent call. + + if ( m_sendImagesDialog->m_mailAgentName->currentText() == "Evolution" ) + { + m_mailAgentProc = new KProcess; + *m_mailAgentProc << "evolution"; + + QString Temp = "mailto:?subject="; + + for ( KURL::List::Iterator it = filelist.begin() ; it != filelist.end() ; ++it ) + { + Temp.append("&attach="); + Temp.append( QFile::encodeName((*it).path()) ); + } + + *m_mailAgentProc << Temp; + + if ( m_mailAgentProc->start() == false ) + KMessageBox::error(kapp->activeWindow(), + i18n("Cannot start '%1' program;\nplease " + "check your installation.") + .arg(m_sendImagesDialog->m_mailAgentName->currentText())); + else + agentInvoked = true; + } + + // Mozilla | Netscape | Thunderbird mail agent call. + + if ( m_sendImagesDialog->m_mailAgentName->currentText() == "Mozilla" || + m_sendImagesDialog->m_mailAgentName->currentText() == "Netscape" || + m_sendImagesDialog->m_mailAgentName->currentText() == "Thunderbird" || + m_sendImagesDialog->m_mailAgentName->currentText() == "GmailAgent") + { + m_mailAgentProc = new KProcess; + + m_thunderbirdUrl = m_sendImagesDialog->m_ThunderbirdBinPath->url(); + + if ( m_sendImagesDialog->m_mailAgentName->currentText() == "Mozilla" ) + { + *m_mailAgentProc << "mozilla" << "-remote"; + } + else if ( m_sendImagesDialog->m_mailAgentName->currentText() == "Thunderbird" ) + { + *m_mailAgentProc << m_thunderbirdUrl << "-remote"; + qDebug("URL: %s", m_thunderbirdUrl.ascii()); + } + else if ( m_sendImagesDialog->m_mailAgentName->currentText() == "GmailAgent" ) + { + *m_mailAgentProc << "gmailagent" << "-remote"; + } + else + { + *m_mailAgentProc << "netscape" << "-remote"; + } + + QString Temp = " xfeDoCommand(composeMessage,attachment='"; + + for ( KURL::List::Iterator it = filelist.begin() ; it != filelist.end() ; ++it ) + { + Temp.append( "file://" ); + QString toencode=(*it).encodedPathAndQuery(); + Temp.append(toencode); + Temp.append( "," ); + } + + Temp.remove(Temp.length()-1,1); + Temp.append("')"); + + *m_mailAgentProc << Temp; + + if (!m_invokedBefore) + { + connect(m_mailAgentProc, SIGNAL(processExited(KProcess *)), + this, SLOT(slotMozillaExited(KProcess*))); + + connect(m_mailAgentProc, SIGNAL(receivedStderr(KProcess *, char*, int)), + this, SLOT(slotMozillaReadStderr(KProcess*, char*, int))); + } + qDebug ("%s", Temp.ascii()); + + if ( m_mailAgentProc->start(KProcess::NotifyOnExit , KProcess::All) == false ) + KMessageBox::error(kapp->activeWindow(), + i18n("Cannot start '%1' program;\nplease " + "check your installation.") + .arg(m_sendImagesDialog->m_mailAgentName->currentText())); + else + { agentInvoked = true; + m_invokedBefore=true; + } + } + } + + return agentInvoked; +} + +///Cleans up the temp directory +void SendImages::removeTmpFiles(void) +{ + if (DeleteDir(m_tmp) == false) + KMessageBox::error(kapp->activeWindow(), i18n("Cannot remove temporary folder %1.").arg(m_tmp)); +} + +///Checks if directory is empty and invokes its deletion +bool SendImages::DeleteDir(QString dirname) +{ + if ( !dirname.isEmpty() ) + { + QDir dir; + + if (dir.exists ( dirname ) == true) + { + if (deldir(dirname) == false) + return false; + + if (dir.rmdir( dirname ) == false ) + return false; + } + else + return false; + } + else + return false; + + return true; +} + +///Deletes a directory and all its contents - Please call it using "DeleteDir" +bool SendImages::deldir(QString dirname) +{ + QDir *dir = new QDir(dirname); + dir->setFilter ( QDir::Dirs | QDir::Files | QDir::NoSymLinks ); + + const QFileInfoList* fileinfolist = dir->entryInfoList(); + QFileInfoListIterator it(*fileinfolist); + QFileInfo* fi; + + while( (fi = it.current() ) ) + { + if(fi->fileName() == "." || fi->fileName() == ".." ) + { + ++it; + continue; + } + + if( fi->isDir() ) + { + if (deldir( fi->absFilePath() ) == false) + return false; + if (dir->rmdir( fi->absFilePath() ) == false) + return false; + } + else + if( fi->isFile() ) + if (dir->remove(fi->absFilePath() ) == false) + return false; + + kapp->processEvents(); + ++it; + } + + return true; +} + +///Returns the file-extension of the corresponding fileformat +QString SendImages::extension(const QString& imageFileFormat) +{ + if (imageFileFormat == "PNG") + return ".png"; + + if (imageFileFormat == "JPEG") + return ".jpg"; + + Q_ASSERT(false); + return ""; +} + +/** in sendimagesplugin dialog the user can select a compression of images + this function returns the pixel-size of the selected entry */ +int SendImages::getSize ( int choice ) +{ + switch (choice) + { + case 0: + return (320); + break; + case 1: + return (640); + break; + case 2: + return (800); + break; + case 3: + return (1024); + break; + case 4: + return (1280); + break; + case 5: + return (1600); + break; + default: + return (800); // Default value... + break; + } +} + +/** This function should copy the images to tempfolder in order to avoid suspicious filenames + It is used, when no resizing should take place + This function can be replaced with Qt4 QFile.copy */ +bool SendImages::copyImageProcess(const QString &oldFilePath, const QString &DestPath, + const QString &ImageName) +{ + //same file, no need to copy + qDebug("DestPath: %s",(DestPath).ascii()); + qDebug("ImageName: %s",(ImageName).ascii()); + if(oldFilePath.compare(DestPath+ImageName) == 0) + return true; + + //load both files + QFile oldFile(oldFilePath); + QFile newFile(DestPath+ImageName); + bool openOld = oldFile.open( IO_ReadOnly ); + bool openNew = newFile.open( IO_WriteOnly ); + + //if either file fails to open bail + if(!openOld || !openNew) { return false; } + + //copy contents + uint BUFFER_SIZE = 16000; + char* buffer = new char[BUFFER_SIZE]; + while(!oldFile.atEnd()) + { + Q_LONG len = oldFile.readBlock( buffer, BUFFER_SIZE ); + newFile.writeBlock( buffer, len ); + } + + //deallocate buffer + delete[] buffer; + buffer = NULL; + return true; +} + +///Resizes the Images before Sending... +bool SendImages::resizeImageProcess(const QString &SourcePath, const QString &DestPath, + const QString &ImageFormat, const QString &ImageName, + int SizeFactor, int ImageCompression, QSize &newsize) +{ + QImage img; + + // Check if RAW file. +#if KDCRAW_VERSION < 0x000106 + QString rawFilesExt(KDcrawIface::DcrawBinary::instance()->rawFiles()); +#else + QString rawFilesExt(KDcrawIface::KDcraw::rawFiles()); +#endif + QFileInfo fileInfo(SourcePath); + if (rawFilesExt.upper().contains( fileInfo.extension(false).upper() )) + KDcrawIface::KDcraw::loadDcrawPreview(img, SourcePath); + else + img.load(SourcePath); + + if ( !img.isNull() ) + { + int w = img.width(); + int h = img.height(); + + if( w > SizeFactor || h > SizeFactor ) + { + if( w > h ) + { + h = (int)( (double)( h * SizeFactor ) / w ); + + if ( h == 0 ) h = 1; + + w = SizeFactor; + Q_ASSERT( h <= SizeFactor ); + } + else + { + w = (int)( (double)( w * SizeFactor ) / h ); + + if ( w == 0 ) w = 1; + + h = SizeFactor; + Q_ASSERT( w <= SizeFactor ); + } + + const QImage scaleImg(img.smoothScale( w, h )); + + if ( scaleImg.width() != w || scaleImg.height() != h ) + { + qDebug ("Resizing failed. Aborting."); + return false; + } + + img = scaleImg; + newsize=img.size(); + } + + if ( !img.save(DestPath + ImageName, ImageFormat.latin1(), ImageCompression) ) + { + qDebug("Saving failed with specific compression value. Aborting."); + return false; + } + + return true; + } + + return false; +} + +/** If mozilla, or thunderbird or any derivate isn't already running, start it now, + wait 5 seconds and start SlotMozillaTimeout() */ +void SendImages::slotMozillaExited(KProcess*) +{ + qDebug("slotMozillaExited"); + ///Here would be the right point to clear the sendlist in order to avoid infinite resendings!! + m_filesSendList.clear(); + ///Also disconnect SLOT + m_mailAgentProc->disconnect(SIGNAL(processExited(KProcess *)), this, SLOT(slotMozillaExited(KProcess*))); + + qDebug("Number of elements in m_filesSendList=%d, and in m_filesSendList_copy=%d)",(int)m_filesSendList.size(),(int)m_filesSendList_copy.size()); + if ( m_mozillaStdErr.find("No running window found") != -1 ) // No remote Mozilla | Netscape | + { // Thunderbird env. loaded ! + m_mailAgentProc2 = new KProcess; // Init a new env. + + if ( m_sendImagesDialog->m_mailAgentName->currentText() == "Mozilla" ) + *m_mailAgentProc2 << "mozilla" << "-mail"; + else if ( m_sendImagesDialog->m_mailAgentName->currentText() == "Thunderbird" ) + *m_mailAgentProc2 << m_thunderbirdUrl << "-mail"; ///for new versions of thunderbird, we don't need it anymore + //*m_mailAgentProc2 << m_thunderbirdUrl; + else + *m_mailAgentProc2 << "netscape" << "-mail"; + + // Start an instance of mozilla mail agent before a remote call. + + if ( m_mailAgentProc2->start() == false ) + { + KMessageBox::error(kapp->activeWindow(), + i18n("Cannot start '%1' program;\nplease " + "check your installation.") + .arg(m_sendImagesDialog->m_mailAgentName->currentText())); + } + else + { + // Mozilla | Netscape | Thunderbird mail agent started correctly + // -> start a remote mail agent with multiple attachments after the env. is loaded ! + + m_mozillaTimer->start(5000, true); + return; + } + } +} + +///If Mozilla wasn't started before, now it is and so we can begin with the transmission +void SendImages::slotMozillaTimeout(void) +{ + m_mozillaTimer->disconnect(SIGNAL(timeout()), this, SLOT(slotMozillaTimeout())); + + qDebug("slotMozillaTimeout: Number of elements in m_filesSendList=%d, and in m_filesSendList_copy=%d)",(int)m_filesSendList.size(),(int)m_filesSendList_copy.size()); + kurllistdeepcopy(m_filesSendList,m_filesSendList_copy); + invokeMailAgent(); + +} + +///Handles mozillas errors +void SendImages::slotMozillaReadStderr(KProcess*, char *buffer, int buflen) +{ + m_mozillaStdErr = QString::fromLocal8Bit(buffer, buflen); +} + +///Makes a deep copy of a KURL-list: Real and slow copying instead of only pointer arithmetics +bool SendImages::kurllistdeepcopy(KURL::List &Destination, KURL::List Source) +{ + Destination.clear(); + qDebug("kurllistdeepcopy started"); + for ( KURL::List::Iterator it = Source.begin() ; it != Source.end() ; ++it ) + { + //QString Tempstring; + QString Getstring=(*it).path(); + QString Tempstring=Getstring.copy(); + Destination.append(Tempstring); + qDebug("%s",Tempstring.ascii()); + } + + /* + qDebug("deepcopytest"); + Source.clear(); + for ( KURL::List::Iterator it = Destination.begin() ; it != Destination.end() ; ++it ) + { + qDebug("%s",(*it).path().ascii()); + } + */ + + qDebug("kurllistdeepcopy ended\n"); + return true; +} + +} // NameSpace KIPISendimagesPlugin diff --git a/kipi-plugins/sendimages/sendimages.h b/kipi-plugins/sendimages/sendimages.h new file mode 100644 index 0000000..762300a --- /dev/null +++ b/kipi-plugins/sendimages/sendimages.h @@ -0,0 +1,190 @@ +/* ============================================================ + * + * This file is a part of kipi-plugins project + * http://www.kipi-plugins.org + * + * Date : 2004-02-25 + * Description : a kipi plugin to e-mailing images + * + * Copyright (C) 2004-2007 by 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, 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. + * + * ============================================================ */ + +#ifndef SENDIMAGES_H +#define SENDIMAGES_H + +// Qt includes. + +#include <qobject.h> +#include <qstring.h> +#include <qthread.h> +#include <qstringlist.h> + +// KDE includes. + +#include <kurl.h> + +// LibKipi includes. + +#include <libkipi/imagecollection.h> +#include <libkipi/interface.h> + +class QFile; +class QTimer; +class QCustomEvent; + +class KProcess; + +namespace KIPISendimagesPlugin +{ + +class SendImagesDialog; + +class SendImages : public QObject, public QThread +{ +Q_OBJECT + +public: + + ///Constructor: saves system handoff parameters in member variables + SendImages(KIPI::Interface* interface, const QString &tmpFolder, + const KIPI::ImageCollection& imagesCollection, QObject *parent=0); + ///Destructor + ~SendImages(); + + ///Prepares the image list. This includes resizing, copying, maintaining an image's exif, + ///and dropping evil characters out of filenames ;-) + virtual void run(); + + ///Invokes the User Dialog Window + void showDialog(void); + + ///Gets input from the user dialog and store it into member variables + void prepare(void); + + ///Shows up an error dialog and the problematic images + bool showErrors(void); + + /// Creates a text file with the images comments. + void makeCommentsFile(void); + + /** Invokes mail agent. Depending on which mail agent to be used, we have different + proceedings. Easy for every agent except of mozilla derivates */ + bool invokeMailAgent(void); + + ///Cleans up the temp directory + void removeTmpFiles(void); + + /** Returns a list of Filenames, whose sum filesize is smaller than the quota + The returned images are deleted from the m_filesSendList*/ + KURL::List divideEmails(void); + +private slots: + + ///If Mozilla wasn't started before, now it is and so we can begin with the transmission + void slotMozillaTimeout(void); + + ///If mozilla, or thunderbird or any derivate isn't already running, + ///start it now, wait 5 seconds and start SlotMozillaTimeout() + void slotMozillaExited(KProcess* proc); + + ///Handles mozillas errors + void slotMozillaReadStderr(KProcess* proc, char *buffer, int buflen); + +private: + + ///Returns the file-extension of the corresponding fileformat + QString extension(const QString& imageFileFormat); + + ///in sendimagesplugin dialog the user can select a compression of images + ///this function returns the pixel-size of the selected entry + int getSize( int choice ); + + ///Checks if directory is empty and invokes its deletion + bool DeleteDir(QString dirname); + + ///Deletes a directory and all its contents - Please call it using "DeleteDir" + bool deldir(QString dirname); + + ///Resizes the Images before Sending... + bool resizeImageProcess(const QString &SourcePath, const QString &DestPath, + const QString &ImageFormat, const QString &ImageName, + int SizeFactor, int ImageCompression, QSize &newsize); + + ///This function should copy the images to tempfolder in order to avoid suspicious filenames + ///It is used, when no resizing should take place + bool copyImageProcess(const QString &oldFilePath, const QString &DestPath, + const QString &ImageName); + + ///Tests if an entry already exists in the filename list + bool entry_already_exists(KURL::List filenamelist,QString entry); + + ///Makes a deep copy of a KURL-list: Real and slow copying instead of only pointer arithmetics + bool kurllistdeepcopy(KURL::List &Destination, KURL::List Source); + +private: + + bool m_invokedBefore; + /** Change image properties options in setup dialog.*/ + + bool m_changeProp; + + /** Image size factor in the setup dialog.*/ + int m_sizeFactor; + + /** Image compression factor in the setup dialog.*/ + int m_imageCompression; + + /** Biggest permitted email.*/ + unsigned long m_attachmentlimit; + + QObject *m_parent; + + QTimer *m_mozillaTimer; + + QString m_mozillaStdErr; + QString m_tmp; + + /** Image format option in the setup dialog.*/ + QString m_imageFormat; + QString m_thunderbirdUrl; + + KProcess *m_mailAgentProc; + KProcess *m_mailAgentProc2; + KProcess *m_mailAgentProc3; + + /** List of images in the setup dialog.*/ + KURL::List m_images; + + /** URL of resized images.*/ + KURL::List m_filesSendList; + KURL::List m_filesSendList_copy; + + /** URL of original images that cannot be resized.*/ + KURL::List m_imagesResizedWithError; + + /** URL of original images than have been resized + and KURL of resized images (used for to create + the comments file).*/ + KURL::List m_imagesPackage; + + KIPI::ImageCollection m_collection; + + KIPI::Interface *m_interface; + + SendImagesDialog *m_sendImagesDialog; +}; + +} // NameSpace KIPISendimagesPlugin + +#endif // SENDIMAGES_H diff --git a/kipi-plugins/sendimages/sendimagesdialog.cpp b/kipi-plugins/sendimages/sendimagesdialog.cpp new file mode 100644 index 0000000..de502bb --- /dev/null +++ b/kipi-plugins/sendimages/sendimagesdialog.cpp @@ -0,0 +1,689 @@ +/* ============================================================ + * + * This file is a part of kipi-plugins project + * http://www.kipi-plugins.org + * + * Date : 2003-10-01 + * Description : a kipi plugin to e-mailing images + * + * Copyright (C) 2003-2007 by Gilles Caulier <caulier dot gilles at gmail dot com> + * Copyright (C) 2006 by Tom Albers <tomalbers at kde dot nl> + * Copyright (C) 2006 by Michael Hoechstetter <michael dot hoechstetter at gmx dot de> + * + * 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. + * + * ============================================================ */ + +// Qt includes. + +#include <qvbox.h> +#include <qlayout.h> +#include <qdir.h> +#include <qwidget.h> +#include <qfile.h> +#include <qtextstream.h> +#include <qlabel.h> +#include <qgroupbox.h> +#include <qwhatsthis.h> +#include <qcombobox.h> +#include <qcheckbox.h> +#include <qprogressdialog.h> +#include <qimage.h> +#include <qevent.h> +#include <qdragobject.h> +#include <qstrlist.h> +#include <qfileinfo.h> +#include <qpushbutton.h> + +// KDE includes. + +#include <klocale.h> +#include <klineedit.h> +#include <kiconloader.h> +#include <kfiledialog.h> +#include <kmessagebox.h> +#include <knuminput.h> +#include <kinstance.h> +#include <kconfig.h> +#include <kdebug.h> +#include <kdialogbase.h> +#include <kbuttonbox.h> +#include <ksqueezedtextlabel.h> +#include <kapplication.h> +#include <khelpmenu.h> +#include <kpopupmenu.h> +#include <kurlrequester.h> + +// LibKipi includes. + +#include <libkipi/imagedialog.h> + +// Local includes. + +#include "kpaboutdata.h" +#include "pluginsversion.h" +#include "listimageserrordialog.h" +#include "sendimagesdialog.h" +#include "sendimagesdialog.moc" + +namespace KIPISendimagesPlugin +{ + +class ImageItem : public QListBoxText +{ + +public: + ImageItem(QListBox * parent, QString const & comments, KURL const & url) + : QListBoxText(parent), _comments(comments), _url(url) + {} + + QString comments() { return _comments; } + QString name() { return _url.fileName(); } + KURL url() { return _url; } + QString album() { return _url.directory().section('/', -1); } + void setName(const QString &newName) { setText(newName); } + +private: + + QString _comments; + KURL _url; +}; + +ListImageItems::ListImageItems(QWidget *parent, const char *name) + : KListBox(parent, name) +{ + setSelectionMode (QListBox::Extended); + setAcceptDrops(true); +} + +void ListImageItems::dragEnterEvent(QDragEnterEvent *e) +{ + e->accept(QUriDrag::canDecode(e)); +} + +void ListImageItems::dropEvent(QDropEvent *e) +{ + QStrList strList; + QStringList FilesPath; + + if ( !QUriDrag::decode(e, strList) ) return; + + QStrList stringList; + QStrListIterator it(strList); + char *str; + + while ( (str = it.current()) != 0 ) + { + QString filePath = QUriDrag::uriToLocalFile(str); + QFileInfo fileInfo(filePath); + + if (fileInfo.isFile() && fileInfo.exists()) + FilesPath.append(fileInfo.filePath()); + + ++it; + } + + if (FilesPath.isEmpty() == false) + emit addedDropItems(FilesPath); +} + +SendImagesDialog::SendImagesDialog(QWidget *parent, KIPI::Interface* interface, + const KIPI::ImageCollection& images ) + : KDialogBase( IconList, i18n("Email Images Options"), Help|Ok|Cancel, + Ok, parent, "SendImagesDialog", false, true ) +{ + m_interface = interface; + m_thumbJob = 0; + + setupImagesList(); + setupEmailOptions(); + readSettings(); + setImagesList( images.images() ); + page_setupImagesList->setFocus(); + m_ImagesFilesListBox->setSelected(0, true); + slotImageSelected(m_ImagesFilesListBox->item(0)); + setNbItems(); + resize( 600, 400 ); + + // About data and help button. + + m_about = new KIPIPlugins::KPAboutData(I18N_NOOP("Send Images"), + 0, + KAboutData::License_GPL, + I18N_NOOP("A Kipi plugin for emailing images"), + "(c) 2003-2007, Gilles Caulier"); + + m_about->addAuthor("Gilles Caulier", I18N_NOOP("Author and maintainer"), + "caulier dot gilles at gmail dot com"); + + m_about->addAuthor("Michael Hoechstetter", I18N_NOOP("Developer"), + "michael dot hoechstetter at gmx dot de"); + + m_about->addAuthor("Tom Albers", I18N_NOOP("Developer"), + "tomalbers at kde dot nl"); + + m_helpButton = actionButton( Help ); + KHelpMenu* helpMenu = new KHelpMenu(this, m_about, false); + helpMenu->menu()->removeItemAt(0); + helpMenu->menu()->insertItem(i18n("Plugin Handbook"), this, SLOT(slotHelp()), 0, -1, 0); + m_helpButton->setPopup( helpMenu->menu() ); + + slotMailAgentChanged(m_mailAgentName->currentItem()); +} + +SendImagesDialog::~SendImagesDialog() +{ + if ( m_thumbJob ) + delete m_thumbJob; + + delete m_about; +} + +void SendImagesDialog::readSettings(void) +{ + // Read all settings from configuration file. + + KConfig config("kipirc"); + config.setGroup("SendImages Settings"); + + QString t = config.readEntry("MailAgentName", "Default"); + + // The _old_ Kmail (mind the lowercase 'm') called the default mailer. + // this is now renamed to 'Default'. It should not interfere with KMail, which + // is now doing what you expect. + + if (t == "Kmail") t = "Default"; + m_mailAgentName->setCurrentText(t); + + m_ThunderbirdBinPath->setURL( config.readEntry("ThunderbirdBinPath", "/usr/bin/mozilla-thunderbird")); + + if (config.readEntry("ImagesChangeProp", "true") == "true") + m_changeImagesProp->setChecked( true ); + else + m_changeImagesProp->setChecked( false ); + + m_imagesResize->setCurrentItem(config.readNumEntry("ImageResize", 2)); // Medium size used by default. + m_imageCompression->setValue(config.readNumEntry("ImageCompression", 75)); + m_imagesFormat->setCurrentText(config.readEntry("ImageFormat", "JPEG")); + m_attachmentlimit->setValue(config.readNumEntry("AttachmentLimit", 10)); + + if (config.readEntry("AddComments", "true") == "true") + m_addComments->setChecked( true ); + else + m_addComments->setChecked( false ); + + if (config.readEntry("Comment2ImageName", "true") == "true") + m_comment2ImageName->setChecked( true ); + else + m_comment2ImageName->setChecked( false ); +} + +void SendImagesDialog::writeSettings(void) +{ + // Write all settings in configuration file. + + KConfig config("kipirc"); + config.setGroup("SendImages Settings"); + config.writeEntry("MailAgentName", m_mailAgentName->currentText()); + config.writeEntry("ThunderbirdBinPath", m_ThunderbirdBinPath->url()); + config.writeEntry("AddComments", m_addComments->isChecked()); + config.writeEntry("ImagesChangeProp", m_changeImagesProp->isChecked()); + config.writeEntry("ImageResize", m_imagesResize->currentItem()); + config.writeEntry("ImageCompression", m_imageCompression->value()); + config.writeEntry("ImageFormat", m_imagesFormat->currentText()); + config.writeEntry("AttachmentLimit", m_attachmentlimit->value()); + config.writeEntry("Comment2ImageName", m_comment2ImageName->isChecked()); + config.sync(); +} + +void SendImagesDialog::setupImagesList(void) +{ + QString whatsThis; + + page_setupImagesList = addPage(i18n("Images"), + i18n("Images to EMail"), + BarIcon("image", KIcon::SizeMedium)); + + QVBoxLayout *vlay = new QVBoxLayout( page_setupImagesList, 0, spacingHint() ); + + //--------------------------------------------- + + m_groupBoxImageList = new QGroupBox( page_setupImagesList ); + m_groupBoxImageList->setFlat(false); + QGridLayout* grid = new QGridLayout( m_groupBoxImageList, 2, 2 , 20, 20); + + m_ImagesFilesListBox = new ListImageItems( m_groupBoxImageList, "ListImageItems" ); + QWhatsThis::add( m_ImagesFilesListBox, i18n( "<p>This is the list of images to email. " + "If you want to add some images click on the 'Add Images...' " + "button or use the drag-and-drop.")); + grid->addMultiCellWidget(m_ImagesFilesListBox, 0, 2, 0, 1); + + KButtonBox* imagesListButtonBox = new KButtonBox( m_groupBoxImageList, Vertical ); + QPushButton* m_addImagesButton = imagesListButtonBox->addButton ( i18n( "&Add ..." ) ); + QWhatsThis::add( m_addImagesButton, i18n("<p>Add images to the list.") ); + QPushButton* m_remImagesButton = imagesListButtonBox->addButton ( i18n( "&Remove" )); + QWhatsThis::add( m_remImagesButton, i18n("<p>Remove selected images from the list.") ); + imagesListButtonBox->layout(); + grid->addMultiCellWidget(imagesListButtonBox, 0, 1, 2, 2); + + m_imageLabel = new QLabel( m_groupBoxImageList ); + m_imageLabel->setFixedHeight( 120 ); + m_imageLabel->setAlignment( Qt::AlignHCenter | Qt::AlignVCenter ); + m_imageLabel->setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ) ); + QWhatsThis::add( m_imageLabel, i18n( "<p>Preview of the currently selected image on the list." ) ); + grid->addMultiCellWidget(m_imageLabel, 2, 2, 2, 2); + + vlay->addWidget( m_groupBoxImageList ); + + //--------------------------------------------- + + QGroupBox * groupBox2 = new QGroupBox( i18n("Image Description"), page_setupImagesList ); + groupBox2->setColumnLayout(0, Qt::Vertical ); + groupBox2->layout()->setSpacing( 6 ); + groupBox2->layout()->setMargin( 11 ); + QWhatsThis::add( groupBox2, i18n("<p>The description of the currently selected image on the list.") ); + + QVBoxLayout * groupBox2Layout = new QVBoxLayout( groupBox2->layout() ); + groupBox2Layout->setAlignment( Qt::AlignTop ); + + m_ImageComments = new KSqueezedTextLabel( groupBox2 ); + m_ImageComments->setAlignment( int( QLabel::WordBreak | QLabel::AlignVCenter ) ); + groupBox2Layout->addWidget( m_ImageComments ); + + m_ImageAlbum = new KSqueezedTextLabel( groupBox2 ); + m_ImageAlbum->setAlignment( int( QLabel::WordBreak | QLabel::AlignVCenter ) ); + groupBox2Layout->addWidget( m_ImageAlbum ); + + vlay->addWidget( groupBox2 ); + vlay->addStretch(1); + + //--------------------------------------------- + + connect(m_addImagesButton, SIGNAL(clicked()), + this, SLOT(slotImagesFilesButtonAdd())); + + connect(m_remImagesButton, SIGNAL(clicked()), + this, SLOT(slotImagesFilesButtonRem())); + + connect(m_ImagesFilesListBox, SIGNAL( currentChanged( QListBoxItem * ) ), + this, SLOT( slotImageSelected( QListBoxItem * ))); + + connect(m_ImagesFilesListBox, SIGNAL( addedDropItems(QStringList) ), + this, SLOT( slotAddDropItems(QStringList))); +} + +void SendImagesDialog::setImagesList( const KURL::List& Files ) +{ + if ( Files.count() == 0 ) return; + + for( KURL::List::ConstIterator it = Files.begin(); it != Files.end(); ++it ) + { + KIPI::ImageInfo imageInfo = m_interface->info( *it ); + QString comments = imageInfo.description(); + + // Check if the new item already exist in the list. + + bool findItem = false; + + for (uint i = 0 ; i < m_ImagesFilesListBox->count() ; ++i) + { + ImageItem *pitem = static_cast<ImageItem*>( m_ImagesFilesListBox->item(i) ); + + if (pitem->url() == (*it)) + findItem = true; + } + + if (findItem == false) + { + ImageItem *item = new ImageItem(m_ImagesFilesListBox, + comments, // Image comments. + *it // Complete url (path & file name). + ); + + item->setName( (*it).fileName() ); + } + } + + m_ImagesFilesListBox->setCurrentItem( m_ImagesFilesListBox->count()-1) ; + slotImageSelected(m_ImagesFilesListBox->item(m_ImagesFilesListBox->currentItem())); + m_ImagesFilesListBox->centerCurrentItem(); +} + +void SendImagesDialog::setupEmailOptions(void) +{ + QString whatsThis; + + page_setupEmailOptions = addPage(i18n("Mail"), + i18n("Mail Options"), + BarIcon("mail_generic", KIcon::SizeMedium)); + + QVBoxLayout *vlay = new QVBoxLayout( page_setupEmailOptions, 0, spacingHint() ); + + //--------------------------------------------- + + QHBoxLayout *hlay10 = new QHBoxLayout( ); + vlay->addLayout( hlay10 ); + + QLabel *m_mailAgentLabel = new QLabel( i18n("Mail agent:"), page_setupEmailOptions); + + m_mailAgentName = new QComboBox( false, page_setupEmailOptions ); + m_mailAgentName->insertItem( i18n("Default") ); + m_mailAgentName->insertItem( "Balsa" ); + m_mailAgentName->insertItem( "Claws Mail" ); + m_mailAgentName->insertItem( "Evolution" ); + m_mailAgentName->insertItem( "GmailAgent" ); + m_mailAgentName->insertItem( "KMail" ); + m_mailAgentName->insertItem( "Mozilla" ); + m_mailAgentName->insertItem( "Netscape" ); + m_mailAgentName->insertItem( "Sylpheed" ); + m_mailAgentName->insertItem( "Sylpheed-Claws" ); + m_mailAgentName->insertItem( "Thunderbird" ); + m_mailAgentName->setCurrentText( i18n("Default") ); + QWhatsThis::add( m_mailAgentName, i18n("<p>Select here your preferred external mail agent program." + "These mail agent versions are supported:<p>" + "<b>Balsa</b>: >= 2.x<p>" + "<b>Claws Mail</b>: >= 2.6.1<p>" + "<b>Evolution</b>: >= 1.4<p>" + "<b>GmailAgent</b>: >= 0.2<p>" + "<b>KMail</b>: >= 1.3<p>" + "<b>Mozilla</b>: >= 1.4<p>" + "<b>Netscape</b>: >= 7.x<p>" + "<b>Sylpheed</b>: >= 0.9<p>" + "<b>Sylpheed-Claws</b>: >= 0.9<p>" + "<b>Thunderbird</b>: >= 0.4<p>") ); + + hlay10->addWidget( m_mailAgentLabel ); + hlay10->addStretch( 1 ); + hlay10->addWidget( m_mailAgentName ); + + connect(m_mailAgentName, SIGNAL(activated(int)), + this, SLOT(slotMailAgentChanged(int))); + + //--------------------------------------------- + + m_labelThunderbirdBinPath = new QLabel(i18n("&Thunderbird binary path:"), page_setupEmailOptions); + vlay->addWidget( m_labelThunderbirdBinPath ); + + m_ThunderbirdBinPath = new KURLRequester( "/usr/bin/thunderbird", page_setupEmailOptions); + m_labelThunderbirdBinPath->setBuddy( m_ThunderbirdBinPath ); + vlay->addWidget(m_ThunderbirdBinPath); + + connect(m_ThunderbirdBinPath, SIGNAL(textChanged(const QString&)), + this, SLOT(slotThunderbirdBinPathChanged(const QString&))); + + QWhatsThis::add( m_ThunderbirdBinPath, i18n("<p>The path name to the Thunderbird binary program.") ); + + //--------------------------------------------- + + m_addComments = new QCheckBox( i18n("Attach a file with caption and tags"), page_setupEmailOptions); + QWhatsThis::add( m_addComments, i18n("<p>If you enable this option, all image captions and tags " + "will be added as an attached file.") ); + vlay->addWidget( m_addComments ); + m_comment2ImageName = new QCheckBox( i18n("Generate new filenames from image captions (if available)"), page_setupEmailOptions); + vlay->addWidget( m_comment2ImageName ); + + //--------------------------------------------- + + QGroupBox * groupBox2 = new QGroupBox( i18n("Image Properties"), page_setupEmailOptions ); + groupBox2->setColumnLayout(0, Qt::Vertical ); + groupBox2->layout()->setSpacing( 6 ); + groupBox2->layout()->setMargin( 11 ); + QWhatsThis::add( groupBox2, i18n("<p>The properties of images to send.") ); + + QVBoxLayout * groupBox2Layout = new QVBoxLayout( groupBox2->layout() ); + groupBox2Layout->setAlignment( Qt::AlignTop ); + + m_changeImagesProp = new QCheckBox(i18n("Adjust image properties"), groupBox2); + QWhatsThis::add( m_changeImagesProp, i18n("<p>If you enable this option, " + "all images to send can be resized and recompressed.") ); + m_changeImagesProp->setChecked( true ); + groupBox2Layout->addWidget( m_changeImagesProp ); + + QHBoxLayout *hlay12 = new QHBoxLayout(); + groupBox2Layout->addLayout( hlay12 ); + + m_imagesResize = new QComboBox(false, groupBox2); + m_imagesResize->insertItem(i18n("Very Small (320 pixels)")); + m_imagesResize->insertItem(i18n("Small (640 pixels)")); + m_imagesResize->insertItem(i18n("Medium (800 pixels)")); + m_imagesResize->insertItem(i18n("Big (1024 pixels)")); + m_imagesResize->insertItem(i18n("Very Big (1280 pixels)")); + m_imagesResize->insertItem(i18n("Huge - for printing (1600 pixels)")); + m_imagesResize->setCurrentText (i18n("Medium (800 pixels)")); + whatsThis = i18n("<p>Select here the images size to send:<p>" + "<b>%1</b>: use this if you have a very slow internet " + "connection or if the target mailbox size is very limited.<p>" + "<b>%2</b>: use this if you have a slow internet connection " + "and if the target mailbox size is limited.<p>" + "<b>%3</b>: this is the default value for a medium internet connection " + "and a target mailbox size.<p>" + "<b>%4</b>: use this if you have a high-speed internet connection " + "and if the target mailbox size is not limited.<p>" + "<b>%5</b>: use this if you have no size or speed restrictions.<p>" + "<b>%6</b>: use this only for printing purpose.<p>") + .arg(i18n("very small (320 pixels)")) + .arg(i18n("small (640 pixels)")) + .arg(i18n("medium (800 pixels)")) + .arg(i18n("big (1024 pixels)")) + .arg(i18n("very big (1280 pixels)")) + .arg(i18n("huge - for printing (1600 pixels)")); + QWhatsThis::add( m_imagesResize, whatsThis ); + + m_labelImageSize = new QLabel( i18n("Sent image size:"), groupBox2); + hlay12->addWidget( m_labelImageSize ); + m_labelImageSize->setBuddy( m_imagesResize ); + hlay12->addStretch( 1 ); + hlay12->addWidget(m_imagesResize); + + //--------------------------------------------- + + m_imageCompression = new KIntNumInput(75, groupBox2); + m_imageCompression->setRange(1, 100, 1, true ); + m_imageCompression->setLabel( i18n("Sent image quality level:") ); + groupBox2Layout->addWidget( m_imageCompression ); + whatsThis = i18n("<p>The new compression value of images to send:<p>"); + whatsThis = whatsThis + i18n("<b>1</b>: very high compression<p>" + "<b>25</b>: high compression<p>" + "<b>50</b>: medium compression<p>" + "<b>75</b>: low compression (default value)<p>" + "<b>100</b>: no compression"); + + QWhatsThis::add( m_imageCompression, whatsThis); + + //--------------------------------------------- + + QHBoxLayout *hlay13 = new QHBoxLayout(); + groupBox2Layout->addLayout( hlay13 ); + + m_imagesFormat = new QComboBox(false, groupBox2); + m_imagesFormat->insertItem("JPEG"); + m_imagesFormat->insertItem("PNG"); + m_imagesFormat->setCurrentText ("JPEG"); + whatsThis = i18n("<p>Select here the images files format to send.<p>"); + whatsThis = whatsThis + i18n("<b>JPEG</b>: The Joint Photographic Experts Group's file format " + "is a good Web file format but it uses lossy compression.<p>" + "<b>PNG</b>: the Portable Network Graphics format is an extensible file format for " + "the lossless, portable, well-compressed storage of raster images. PNG provides a " + "patent-free replacement for GIF and can also replace many common uses of TIFF. " + "PNG is designed to work well in online viewing applications, such as the World Wide Web, " + "so it is fully streamable with a progressive display option. Also, PNG can store gamma " + "and chromaticity data for improved color matching on heterogeneous platforms."); + QWhatsThis::add( m_imagesFormat, whatsThis ); + + m_labelImageFormat = new QLabel(i18n("Image file format:"), groupBox2); + hlay13->addWidget(m_labelImageFormat); + m_labelImageFormat->setBuddy(m_imagesFormat); + hlay13->addStretch(1); + hlay13->addWidget(m_imagesFormat); + + vlay->addWidget(groupBox2); + vlay->addStretch(1); + + m_attachmentlimit = new KIntNumInput(17, page_setupEmailOptions); + m_attachmentlimit->setRange(1, 50, 1, true ); + m_attachmentlimit->setLabel( i18n("Maximum Email size limit:")); + m_attachmentlimit->setSuffix(i18n("MB")); + vlay->addWidget( m_attachmentlimit ); + + //--------------------------------------------- + + connect(m_changeImagesProp, SIGNAL(toggled(bool)), + m_labelImageSize, SLOT(setEnabled(bool))); + + connect(m_changeImagesProp, SIGNAL(toggled(bool)), + m_imagesResize, SLOT(setEnabled(bool))); + + connect(m_changeImagesProp, SIGNAL(toggled(bool)), + m_imageCompression, SLOT(setEnabled(bool))); + + connect(m_changeImagesProp, SIGNAL(toggled(bool)), + m_labelImageFormat, SLOT(setEnabled(bool))); + + connect(m_changeImagesProp, SIGNAL(toggled(bool)), + m_imagesFormat, SLOT(setEnabled(bool))); +} + +void SendImagesDialog::slotHelp() +{ + KApplication::kApplication()->invokeHelp("sendimages", "kipi-plugins"); +} + +void SendImagesDialog::slotMailAgentChanged(int) +{ + if ( m_mailAgentName->currentText() == "Thunderbird" ) + { + m_labelThunderbirdBinPath->setEnabled(true); + m_ThunderbirdBinPath->setEnabled(true); + } + else + { + m_labelThunderbirdBinPath->setEnabled(false); + m_ThunderbirdBinPath->setEnabled(false); + } +} + +void SendImagesDialog::slotThunderbirdBinPathChanged(const QString &url ) +{ + if ( m_mailAgentName->currentText() == "Thunderbird" ) + enableButtonOK( !url.isEmpty()); +} + +void SendImagesDialog::slotAddDropItems(QStringList filesPath) +{ + setImagesList( KURL::List( filesPath) ); +} + +void SendImagesDialog::slotImagesFilesButtonAdd( void ) +{ + KURL::List urls = KIPI::ImageDialog::getImageURLs( this, m_interface ); + + if ( urls.isEmpty() ) return; + + setImagesList(urls); + setNbItems(); +} + +void SendImagesDialog::slotImagesFilesButtonRem( void ) +{ + for (uint i = 0 ; i < m_ImagesFilesListBox->count() ; ++i) + { + if (m_ImagesFilesListBox->isSelected(i)) + { + m_ImagesFilesListBox->removeItem(i); + m_ImagesFilesListBox->setCurrentItem(i); + --i; + } + } + + m_ImagesFilesListBox->setSelected(m_ImagesFilesListBox->item(m_ImagesFilesListBox->currentItem()), true); + slotImageSelected(m_ImagesFilesListBox->item(m_ImagesFilesListBox->currentItem())); + setNbItems(); +} + +void SendImagesDialog::slotImageSelected( QListBoxItem * item ) +{ + if ( !item || m_ImagesFilesListBox->count() == 0 ) + { + m_imageLabel->clear(); + return; + } + + ImageItem *pitem = static_cast<ImageItem*>( item ); + + if ( !pitem ) return; + + m_ImageComments->setText( i18n("Caption: %1").arg(pitem->comments()) ); + m_ImageAlbum->setText( i18n("Album: %1").arg(pitem->album()) ); + m_imageLabel->clear(); + + if ( m_thumbJob ) + delete m_thumbJob; + + m_thumbJob = KIO::filePreview( pitem->url(), m_imageLabel->height() ); + + connect(m_thumbJob, SIGNAL(gotPreview(const KFileItem*, const QPixmap&)), + SLOT(slotGotPreview(const KFileItem*, const QPixmap&))); + + connect(m_thumbJob, SIGNAL(failed(const KFileItem*)), + SLOT(slotFailedPreview(const KFileItem*))); +} + +void SendImagesDialog::slotGotPreview(const KFileItem*, const QPixmap &pixmap) +{ + m_imageLabel->setPixmap(pixmap); + m_thumbJob = 0L; +} + +void SendImagesDialog::slotFailedPreview(const KFileItem*) +{ + m_thumbJob = 0L; +} + +void SendImagesDialog::slotOk() +{ + if ( m_ImagesFilesListBox->count() == 0 ) + { + KMessageBox::error(this, i18n("You must add some images to send.")); + return; + } + + if ( m_mailAgentName->currentText() == "Thunderbird" ) + { + QFile fileThunderbird(m_ThunderbirdBinPath->url()); + + if (fileThunderbird.exists() == false) + { + KMessageBox::sorry(this, i18n("Thunderbird binary path is not valid. Please check it.")); + return; + } + } + + writeSettings(); + + for (uint i = 0 ; i < m_ImagesFilesListBox->count() ; i++) + { + ImageItem *pitem = static_cast<ImageItem*>( m_ImagesFilesListBox->item(i) ); + m_images2send << pitem->url(); + } + + emit signalAccepted(); + accept(); +} + +void SendImagesDialog::setNbItems(void) +{ + if ( m_ImagesFilesListBox->count() == 0 ) m_groupBoxImageList->setTitle(i18n("Image List")); + else + m_groupBoxImageList->setTitle(i18n("Image List (1 item)", "Image List (%n items)", + m_ImagesFilesListBox->count() )); +} + +} // NameSpace KIPISendimagesPlugin diff --git a/kipi-plugins/sendimages/sendimagesdialog.h b/kipi-plugins/sendimages/sendimagesdialog.h new file mode 100644 index 0000000..3fd4984 --- /dev/null +++ b/kipi-plugins/sendimages/sendimagesdialog.h @@ -0,0 +1,173 @@ +/* ============================================================ + * + * This file is a part of kipi-plugins project + * http://www.kipi-plugins.org + * + * Date : 2003-10-01 + * Description : a kipi plugin to e-mailing images + * + * Copyright (C) 2003-2007 by 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, 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. + * + * ============================================================ */ + +#ifndef SENDIMAGESDIALOG_H +#define SENDIMAGESDIALOG_H + +// Qt includes. + +#include <qstring.h> +#include <qguardedptr.h> + +// KDE includes. + +#include <kdialogbase.h> +#include <klistbox.h> +#include <kio/previewjob.h> +#include <kurl.h> + +// LibKipi includes. + +#include <libkipi/interface.h> +#include <libkipi/imagecollection.h> +#include <libkipi/imageinfo.h> + +// Local includes. + +#include "kpaboutdata.h" + +class QComboBox; +class QGroupBox; +class QLabel; +class QCheckBox; +class QFrame; +class QPushButton; +class QFileInfo; + +class KFileItem; +class KIntNumInput; +class KListBox; +class KSqueezedTextLabel; +class KURLRequester; + +namespace KIPISendimagesPlugin +{ + +class ListImageItems : public KListBox +{ + Q_OBJECT + +public: + + ListImageItems(QWidget *parent=0, const char *name=0); + +signals: + + void addedDropItems(QStringList filesPath); + +protected: + + void dragEnterEvent(QDragEnterEvent *e); + void dropEvent(QDropEvent *e); +}; + + +class SendImagesDialog : public KDialogBase +{ + Q_OBJECT + +public: + + SendImagesDialog(QWidget *parent, KIPI::Interface* interface, + const KIPI::ImageCollection& images ); + ~SendImagesDialog(); + + KIntNumInput *m_imageCompression; + KIntNumInput *m_attachmentlimit; + + QComboBox *m_imagesFormat; + QComboBox *m_imagesResize; + QComboBox *m_mailAgentName; + + QCheckBox *m_addComments; + QCheckBox *m_comment2ImageName; + QCheckBox *m_changeImagesProp; + + KURLRequester *m_ThunderbirdBinPath; + + KURL::List m_images2send; + +public slots: + + void slotAddDropItems(QStringList filesPath); + +signals: + + void signalAccepted(void); + +private slots: + + void slotHelp(); + void slotOk(); + void slotImageSelected( QListBoxItem * item ); + void slotGotPreview(const KFileItem* , const QPixmap &pixmap); + void slotFailedPreview(const KFileItem*); + void slotImagesFilesButtonAdd(void); + void slotImagesFilesButtonRem(void); + void slotThunderbirdBinPathChanged(const QString&); + void slotMailAgentChanged(int); + +private: + + void setupImagesList(void); + void setupEmailOptions(void); + void setImagesList(const KURL::List& images); + void writeSettings(void); + void readSettings(void); + void setNbItems(void); + +private: + + bool m_cancelled; + + QLabel *m_labelImageFormat; + QLabel *m_labelImageSize; + QLabel *m_mailAgentLabel; + QLabel *m_labelThunderbirdBinPath; + + QPushButton *m_addImageButton; + QPushButton *m_remImagesButton; + QPushButton *m_helpButton; + + QProgressDialog *m_progressDlg; + + QGroupBox *m_groupBoxImageList; + + QLabel *m_imageLabel; + + QFrame *page_setupImagesList; + QFrame *page_setupEmailOptions; + QFrame *page_about; + + KSqueezedTextLabel *m_ImageComments; + KSqueezedTextLabel *m_ImageAlbum; + + KIPI::Interface *m_interface; + KIO::PreviewJob *m_thumbJob; + + KIPIPlugins::KPAboutData *m_about; + ListImageItems *m_ImagesFilesListBox; +}; + +} // NameSpace KIPISendimagesPlugin + +#endif // SENDIMAGESDIALOG_H |