~ubuntu-branches/ubuntu/edgy/gwenview/edgy

« back to all changes in this revision

Viewing changes to src/gvdirpart/gvdirpart.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2005-12-06 17:59:19 UTC
  • mfrom: (1.1.3 upstream) (2.1.1 sarge)
  • Revision ID: james.westby@ubuntu.com-20051206175919-8yv9nfmw0pws6p52
Tags: 1.3.1-0ubuntu1
* Sync with Debian
* Edit kde.mk for .pot generation

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
Copyright 2004 Jonathan Riddell <jr@jriddell.org>
 
3
 
 
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.
 
8
 
 
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.
 
13
 
 
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.
 
17
 
 
18
*/
 
19
#include "gvdirpart.moc"
 
20
 
 
21
#include <qcursor.h>
 
22
#include <qfile.h>
 
23
#include <qsplitter.h>
 
24
#include <qvaluelist.h>
 
25
 
 
26
#include <kdebug.h>
 
27
#include <kdeversion.h>
 
28
#include <kaction.h>
 
29
#include <kicontheme.h>
 
30
#include <kiconloader.h>
 
31
#include <klocale.h>
 
32
#include <kstandarddirs.h>
 
33
#include <kparts/browserextension.h>
 
34
#include <kparts/genericfactory.h>
 
35
#include <kio/job.h>
 
36
 
 
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>
 
48
 
 
49
#include "config.h"
 
50
 
 
51
namespace Gwenview {
 
52
 
 
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";
 
60
 
 
61
 
 
62
class GVDirPartImageView : public ImageView {
 
63
public:
 
64
        GVDirPartImageView(QWidget* parent, Document* document, KActionCollection* actionCollection, GVDirPartBrowserExtension* browserExtension)
 
65
        : ImageView(parent, document, actionCollection), mBrowserExtension(browserExtension)
 
66
        {}
 
67
 
 
68
protected:
 
69
        void openContextMenu(const QPoint&) {
 
70
                mBrowserExtension->contextMenu();
 
71
        }
 
72
 
 
73
private:
 
74
        GVDirPartBrowserExtension* mBrowserExtension;
 
75
};
 
76
 
 
77
 
 
78
class GVDirPartFileView : public FileViewStack {
 
79
public:
 
80
        GVDirPartFileView(QWidget* parent, KActionCollection* actionCollection, GVDirPartBrowserExtension* browserExtension)
 
81
        : FileViewStack(parent, actionCollection)
 
82
        , mBrowserExtension(browserExtension) {}
 
83
 
 
84
protected:
 
85
        virtual void openContextMenu(const QPoint& pos, bool onItem) {
 
86
                if (onItem) {
 
87
                        const KFileItemList* items=currentFileView()->selectedItems();
 
88
                        emit mBrowserExtension->popupMenu(pos, *items);
 
89
                } else {
 
90
                        emit mBrowserExtension->popupMenu(pos, dirURL(), 0);
 
91
                }
 
92
        }
 
93
 
 
94
private:
 
95
        GVDirPartBrowserExtension* mBrowserExtension;
 
96
};
 
97
 
 
98
 
 
99
//Factory Code
 
100
typedef KParts::GenericFactory<GVDirPart> GVDirFactory;
 
101
K_EXPORT_COMPONENT_FACTORY( libgvdirpart /*library name*/, GVDirFactory )
 
102
 
 
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" );
 
108
 
 
109
        mBrowserExtension = new GVDirPartBrowserExtension(this);
 
110
        mBrowserExtension->updateActions();
 
111
 
 
112
        mSplitter = new QSplitter(Qt::Horizontal, parentWidget, "gwenview-kpart-splitter");
 
113
        mSplitter->setFocusPolicy(QWidget::ClickFocus);
 
114
 
 
115
        // Create the widgets
 
116
        mDocument = new Document(this);
 
117
        mFilesView = new GVDirPartFileView(mSplitter, actionCollection(), mBrowserExtension);
 
118
        mImageView = new GVDirPartImageView(mSplitter, mDocument, actionCollection(), mBrowserExtension);
 
119
 
 
120
        mSlideShow = new SlideShow(mDocument);
 
121
 
 
122
        FileOperation::kpartConfig();
 
123
        mFilesView->kpartConfig();
 
124
 
 
125
        setWidget(mSplitter);
 
126
 
 
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");
 
129
 
 
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&)) );
 
138
 
 
139
        QValueList<int> splitterSizes;
 
140
        splitterSizes.append(20);
 
141
        mSplitter->setSizes(splitterSizes);
 
142
 
 
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" ));
 
146
#endif
 
147
 
 
148
        setXMLFile( "gvdirpart/gvdirpart.rc" );
 
149
}
 
150
 
 
151
GVDirPart::~GVDirPart() {
 
152
        delete mSlideShow;
 
153
}
 
154
 
 
155
 
 
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);
 
164
        } else {
 
165
                mImageView->writeConfig(config, CONFIG_VIEW_GROUP);
 
166
        }
 
167
        delete config;
 
168
}
 
169
 
 
170
 
 
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>");
 
176
        return aboutData;
 
177
}
 
178
 
 
179
bool GVDirPart::openFile() {
 
180
        //unused because openURL implemented
 
181
 
 
182
        //mDocument->setFilename(mFile);
 
183
        return true;
 
184
}
 
185
 
 
186
bool GVDirPart::openURL(const KURL& url) {
 
187
        if (!url.isValid()) {
 
188
                return false;
 
189
        }
 
190
 
 
191
        emit started( 0 );
 
192
        m_url = url;
 
193
        m_url.adjustPath(1);
 
194
 
 
195
        emit setWindowCaption( m_url.prettyURL() );
 
196
        mFilesView->setDirURL(m_url);
 
197
 
 
198
        return true;
 
199
}
 
200
 
 
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);
 
206
        emit completed();
 
207
}
 
208
 
 
209
KURL GVDirPart::pixmapURL() {
 
210
        return mDocument->url();
 
211
}
 
212
 
 
213
void GVDirPart::toggleSlideShow() {
 
214
        if (mToggleSlideShow->isChecked()) {
 
215
                SlideShowDialog dialog(mSplitter, mSlideShow);
 
216
                if (!dialog.exec()) {
 
217
                        mToggleSlideShow->setChecked(false);
 
218
                        return;
 
219
                }
 
220
        KURL::List list;
 
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());
 
226
            }
 
227
        }
 
228
        if (list.count()==0) {
 
229
                        mToggleSlideShow->setChecked(false);
 
230
            return;
 
231
        }
 
232
                //FIXME turn on full screen here (anyone know how?)
 
233
                mSlideShow->start(list);
 
234
        } else {
 
235
                //FIXME turn off full screen here
 
236
                mSlideShow->stop();
 
237
        }
 
238
}
 
239
 
 
240
void GVDirPart::print() {
 
241
        KPrinter printer;
 
242
        if ( !mDocument->filename().isEmpty() ) {
 
243
                printer.setDocName( m_url.filename() );
 
244
                KPrinter::addDialogPage( new PrintDialogPage( mDocument, mImageView, "GV page"));
 
245
 
 
246
                if (printer.setup(mImageView, QString::null, true)) {
 
247
                        mDocument->print(&printer);
 
248
                }
 
249
        }
 
250
}
 
251
 
 
252
void GVDirPart::rotateRight() {
 
253
        mDocument->transform(ImageUtils::ROT_90);
 
254
}
 
255
 
 
256
void GVDirPart::directoryChanged(const KURL& dirURL) {
 
257
        if( dirURL == m_url ) return;
 
258
        emit mBrowserExtension->openURLRequest(dirURL);
 
259
}
 
260
 
 
261
void GVDirPart::urlChanged(const KURL& url) {
 
262
        mDocument->setURL( url );
 
263
        mFilesView->setFileNameToSelect( url.filename());
 
264
}
 
265
 
 
266
 
 
267
/***** GVDirPartBrowserExtension *****/
 
268
 
 
269
GVDirPartBrowserExtension::GVDirPartBrowserExtension(GVDirPart* viewPart, const char* name)
 
270
        :KParts::BrowserExtension(viewPart, name) {
 
271
        mGVDirPart = viewPart;
 
272
        emit enableAction("print", true );
 
273
}
 
274
 
 
275
GVDirPartBrowserExtension::~GVDirPartBrowserExtension() {
 
276
}
 
277
 
 
278
void GVDirPartBrowserExtension::updateActions() {
 
279
        /*
 
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 );
 
285
        */
 
286
}
 
287
 
 
288
void GVDirPartBrowserExtension::del() {
 
289
        kdDebug() << k_funcinfo << endl;
 
290
}
 
291
 
 
292
void GVDirPartBrowserExtension::trash() {
 
293
        kdDebug() << k_funcinfo << endl;
 
294
}
 
295
 
 
296
void GVDirPartBrowserExtension::editMimeType() {
 
297
        kdDebug() << k_funcinfo << endl;
 
298
}
 
299
 
 
300
void GVDirPartBrowserExtension::refresh() {
 
301
        kdDebug() << k_funcinfo << endl;
 
302
}
 
303
 
 
304
void GVDirPartBrowserExtension::copy() {
 
305
        kdDebug() << k_funcinfo << endl;
 
306
}
 
307
void GVDirPartBrowserExtension::cut() {
 
308
        kdDebug() << k_funcinfo << endl;
 
309
}
 
310
 
 
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);
 
320
        */
 
321
        emit popupMenu(QCursor::pos(), mGVDirPart->pixmapURL(), 0);
 
322
}
 
323
 
 
324
void GVDirPartBrowserExtension::print() {
 
325
        mGVDirPart->print();
 
326
}
 
327
 
 
328
} // namespace