1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
|
/* ============================================================
*
* 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 <tdelocale.h>
#include <tdeapplication.h>
#include <tdeglobal.h>
#include <tdeaction.h>
#include <kgenericfactory.h>
#include <klibloader.h>
#include <tdeconfig.h>
#include <kdebug.h>
#include <kiconloader.h>
#include <kinstance.h>
#include <tdemessagebox.h>
#include <kstandarddirs.h>
#include <tdetempfile.h>
#include <kimageio.h>
#include <tdeversion.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(TQObject *parent, const char*, const TQStringList&)
: KIPI::Plugin( Factory::instance(), parent, "SendImages")
{
kdDebug( 51001 ) << "Plugin_SendImages plugin loaded" << endl;
}
void Plugin_SendImages::setup( TQWidget* widget )
{
KIPI::Plugin::setup( widget );
m_action_sendimages = new TDEAction (i18n("Email Images..."), // Menu message.
"mail-message-new", // Menu icon.
0,
this,
TQT_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, TQT_SIGNAL(selectionChanged(bool)),
m_action_sendimages, TQT_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;
TDEStandardDirs dir;
TQString Tmp = dir.saveLocation("tmp", "kipi-sendimagesplugin-" + TQString::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(TQCustomEvent *event)
{
if (!event) return;
if (!m_progressDlg)
{
m_progressDlg = new KIPI::BatchProgressDialog(kapp->activeWindow(), i18n("Preparing images to send"));
connect(m_progressDlg, TQT_SIGNAL(cancelClicked()),
this, TQT_SLOT(slotCancel()));
m_current = 0;
m_progressDlg->show();
}
KIPISendimagesPlugin::EventData *d = (KIPISendimagesPlugin::EventData*) event->data();
if (!d) return;
if (d->starting)
{
TQString 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
{
TQString 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 TDE_VERSION >= 0x30200
m_progressDlg->setButtonCancel( KStdGuiItem::close() );
#else
m_progressDlg->setButtonCancelText( i18n("&Close") );
#endif
disconnect(m_progressDlg, TQT_SIGNAL(cancelClicked()),
this, TQT_SLOT(slotCancel()));
// 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( TDEAction* 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
}
|