2
Copyright 2004 Jonathan Riddell <jr@jriddell.org>
4
This program is free software; you can redistribute it and/or
5
modify it under the terms of the GNU General Public License
6
as published by the Free Software Foundation; either version 2
7
of the License, or (at your option) any later version.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public License
15
along with this program; if not, write to the Free Software
16
Foundation, Inc., 51 Franklin Steet, Fifth Floor, Boston, MA 02111-1307, USA.
19
#include "gvdirpart.moc"
23
#include <qsplitter.h>
24
#include <qvaluelist.h>
27
#include <kdeversion.h>
29
#include <kicontheme.h>
30
#include <kiconloader.h>
32
#include <kstandarddirs.h>
33
#include <kparts/browserextension.h>
34
#include <kparts/genericfactory.h>
37
#include <gvcore/fileoperation.h>
38
#include <gvcore/archive.h>
39
#include <gvcore/cache.h>
40
#include <gvcore/document.h>
41
#include <gvcore/fileviewbase.h>
42
#include <gvcore/fileviewstack.h>
43
#include <gvcore/printdialog.h>
44
#include <gvcore/imageview.h>
45
#include <gvcore/slideshowdialog.h>
46
#include <gvcore/slideshow.h>
47
#include <gvcore/thumbnailloadjob.h>
53
// For now let's duplicate
54
const char CONFIG_CACHE_GROUP[]="cache";
55
const char CONFIG_FILEOPERATION_GROUP[]="file operations";
56
const char CONFIG_JPEGTRAN_GROUP[]="jpegtran";
57
const char CONFIG_SLIDESHOW_GROUP[]="slide show";
58
const char CONFIG_THUMBNAILLOADJOB_GROUP[]="thumbnail loading";
59
const char CONFIG_VIEW_GROUP[]="GwenviewPart View";
62
class GVDirPartImageView : public ImageView {
64
GVDirPartImageView(QWidget* parent, Document* document, KActionCollection* actionCollection, GVDirPartBrowserExtension* browserExtension)
65
: ImageView(parent, document, actionCollection), mBrowserExtension(browserExtension)
69
void openContextMenu(const QPoint&) {
70
mBrowserExtension->contextMenu();
74
GVDirPartBrowserExtension* mBrowserExtension;
78
class GVDirPartFileView : public FileViewStack {
80
GVDirPartFileView(QWidget* parent, KActionCollection* actionCollection, GVDirPartBrowserExtension* browserExtension)
81
: FileViewStack(parent, actionCollection)
82
, mBrowserExtension(browserExtension) {}
85
virtual void openContextMenu(const QPoint& pos, bool onItem) {
87
const KFileItemList* items=currentFileView()->selectedItems();
88
emit mBrowserExtension->popupMenu(pos, *items);
90
emit mBrowserExtension->popupMenu(pos, dirURL(), 0);
95
GVDirPartBrowserExtension* mBrowserExtension;
100
typedef KParts::GenericFactory<GVDirPart> GVDirFactory;
101
K_EXPORT_COMPONENT_FACTORY( libgvdirpart /*library name*/, GVDirFactory )
103
GVDirPart::GVDirPart(QWidget* parentWidget, const char* /*widgetName*/, QObject* parent, const char* name,
104
const QStringList &) : KParts::ReadOnlyPart( parent, name ) {
105
GVDirFactory::instance()->iconLoader()->addAppDir( "gwenview");
106
setInstance( GVDirFactory::instance() );
107
KGlobal::locale()->insertCatalogue( "gwenview" );
109
mBrowserExtension = new GVDirPartBrowserExtension(this);
110
mBrowserExtension->updateActions();
112
mSplitter = new QSplitter(Qt::Horizontal, parentWidget, "gwenview-kpart-splitter");
113
mSplitter->setFocusPolicy(QWidget::ClickFocus);
115
// Create the widgets
116
mDocument = new Document(this);
117
mFilesView = new GVDirPartFileView(mSplitter, actionCollection(), mBrowserExtension);
118
mImageView = new GVDirPartImageView(mSplitter, mDocument, actionCollection(), mBrowserExtension);
120
mSlideShow = new SlideShow(mDocument);
122
FileOperation::kpartConfig();
123
mFilesView->kpartConfig();
125
setWidget(mSplitter);
127
KStdAction::saveAs( mDocument, SLOT(saveAs()), actionCollection(), "saveAs" );
128
new KAction(i18n("Rotate &Right"), "rotate_cw", CTRL + Key_R, this, SLOT(rotateRight()), actionCollection(), "rotate_right");
130
connect(mFilesView, SIGNAL(urlChanged(const KURL&)),
131
this, SLOT(urlChanged(const KURL&)) );
132
connect(mFilesView, SIGNAL(directoryChanged(const KURL&)),
133
this, SLOT(directoryChanged(const KURL&)) );
134
connect(mSlideShow, SIGNAL(nextURL(const KURL&)),
135
this, SLOT(urlChanged(const KURL&)) );
136
connect(mDocument, SIGNAL(loaded(const KURL&)),
137
this, SLOT(loaded(const KURL&)) );
139
QValueList<int> splitterSizes;
140
splitterSizes.append(20);
141
mSplitter->setSizes(splitterSizes);
143
mToggleSlideShow = new KToggleAction(i18n("Slide Show..."), "slideshow", 0, this, SLOT(toggleSlideShow()), actionCollection(), "slideshow");
144
#if KDE_IS_VERSION(3, 3, 0)
145
mToggleSlideShow->setCheckedState( i18n("Stop Slide Show" ));
148
setXMLFile( "gvdirpart/gvdirpart.rc" );
151
GVDirPart::~GVDirPart() {
156
void GVDirPart::partActivateEvent(KParts::PartActivateEvent* event) {
157
KConfig* config=new KConfig("gwenviewrc");
158
if (event->activated()) {
159
FileOperation::readConfig(config, CONFIG_FILEOPERATION_GROUP);
160
mSlideShow->readConfig(config, CONFIG_SLIDESHOW_GROUP);
161
mImageView->readConfig(config, CONFIG_VIEW_GROUP);
162
ThumbnailLoadJob::readConfig(config,CONFIG_THUMBNAILLOADJOB_GROUP);
163
Cache::instance()->readConfig(config,CONFIG_CACHE_GROUP);
165
mImageView->writeConfig(config, CONFIG_VIEW_GROUP);
171
KAboutData* GVDirPart::createAboutData() {
172
KAboutData* aboutData = new KAboutData( "gvdirpart", I18N_NOOP("GVDirPart"),
173
"0.1", I18N_NOOP("Image Browser"),
174
KAboutData::License_GPL,
175
"(c) 2004, Jonathan Riddell <jr@jriddell.org>");
179
bool GVDirPart::openFile() {
180
//unused because openURL implemented
182
//mDocument->setFilename(mFile);
186
bool GVDirPart::openURL(const KURL& url) {
187
if (!url.isValid()) {
195
emit setWindowCaption( m_url.prettyURL() );
196
mFilesView->setDirURL(m_url);
201
void GVDirPart::loaded(const KURL& url) {
202
QString caption = url.filename();
203
if( !mDocument->image().isNull())
204
caption += QString(" %1 x %2").arg(mDocument->width()).arg(mDocument->height());
205
emit setWindowCaption(caption);
209
KURL GVDirPart::pixmapURL() {
210
return mDocument->url();
213
void GVDirPart::toggleSlideShow() {
214
if (mToggleSlideShow->isChecked()) {
215
SlideShowDialog dialog(mSplitter, mSlideShow);
216
if (!dialog.exec()) {
217
mToggleSlideShow->setChecked(false);
221
KFileItemListIterator it( *mFilesView->currentFileView()->items() );
222
for ( ; it.current(); ++it ) {
223
KFileItem* item=it.current();
224
if (!item->isDir() && !Archive::fileItemIsArchive(item)) {
225
list.append(item->url());
228
if (list.count()==0) {
229
mToggleSlideShow->setChecked(false);
232
//FIXME turn on full screen here (anyone know how?)
233
mSlideShow->start(list);
235
//FIXME turn off full screen here
240
void GVDirPart::print() {
242
if ( !mDocument->filename().isEmpty() ) {
243
printer.setDocName( m_url.filename() );
244
KPrinter::addDialogPage( new PrintDialogPage( mDocument, mImageView, "GV page"));
246
if (printer.setup(mImageView, QString::null, true)) {
247
mDocument->print(&printer);
252
void GVDirPart::rotateRight() {
253
mDocument->transform(ImageUtils::ROT_90);
256
void GVDirPart::directoryChanged(const KURL& dirURL) {
257
if( dirURL == m_url ) return;
258
emit mBrowserExtension->openURLRequest(dirURL);
261
void GVDirPart::urlChanged(const KURL& url) {
262
mDocument->setURL( url );
263
mFilesView->setFileNameToSelect( url.filename());
267
/***** GVDirPartBrowserExtension *****/
269
GVDirPartBrowserExtension::GVDirPartBrowserExtension(GVDirPart* viewPart, const char* name)
270
:KParts::BrowserExtension(viewPart, name) {
271
mGVDirPart = viewPart;
272
emit enableAction("print", true );
275
GVDirPartBrowserExtension::~GVDirPartBrowserExtension() {
278
void GVDirPartBrowserExtension::updateActions() {
280
emit enableAction( "copy", true );
281
emit enableAction( "cut", true );
282
emit enableAction( "trash", true);
283
emit enableAction( "del", true );
284
emit enableAction( "editMimeType", true );
288
void GVDirPartBrowserExtension::del() {
289
kdDebug() << k_funcinfo << endl;
292
void GVDirPartBrowserExtension::trash() {
293
kdDebug() << k_funcinfo << endl;
296
void GVDirPartBrowserExtension::editMimeType() {
297
kdDebug() << k_funcinfo << endl;
300
void GVDirPartBrowserExtension::refresh() {
301
kdDebug() << k_funcinfo << endl;
304
void GVDirPartBrowserExtension::copy() {
305
kdDebug() << k_funcinfo << endl;
307
void GVDirPartBrowserExtension::cut() {
308
kdDebug() << k_funcinfo << endl;
311
void GVDirPartBrowserExtension::contextMenu() {
312
/*FIXME Why is this KFileMetaInfo invalid?
313
KFileMetaInfo metaInfo = KFileMetaInfo(m_gvImagePart->filePath());
314
kdDebug() << k_funcinfo << "m_gvImagePart->filePath(): " << m_gvImagePart->filePath() << endl;
315
kdDebug() << k_funcinfo << "metaInfo.isValid(): " << metaInfo.isValid() << endl;
316
kdDebug() << k_funcinfo << "above" << endl;
317
QString mimeType = metaInfo.mimeType();
318
kdDebug() << k_funcinfo << "below" << endl;
319
emit popupMenu(QCursor::pos(), m_gvImagePart->url(), mimeType);
321
emit popupMenu(QCursor::pos(), mGVDirPart->pixmapURL(), 0);
324
void GVDirPartBrowserExtension::print() {