~ubuntu-branches/ubuntu/intrepid/gwenview/intrepid

« back to all changes in this revision

Viewing changes to gvdirpart/gvdirpart.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Christopher Martin
  • Date: 2005-04-06 11:33:06 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20050406113306-7zovl7z0io5bacpd
Tags: 1.2.0-1
* New upstream release.
  + Fixes crashes when using "Back" to navigate. (Closes: #301811)
* Enable KIPI support.
* Add a doc-base file for the handbook.

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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
17
 
 
18
*/
 
19
#include <qcursor.h>
 
20
#include <qfile.h>
 
21
#include <qsplitter.h>
 
22
#include <qvaluelist.h>
 
23
 
 
24
#include <kdebug.h>
 
25
#include <kaction.h>
 
26
#include <kicontheme.h>
 
27
#include <kiconloader.h>
 
28
#include <klocale.h>
 
29
#include <kstandarddirs.h>
 
30
#include <kparts/browserextension.h>
 
31
#include <kparts/genericfactory.h>
 
32
#include <kio/job.h>
 
33
 
 
34
#include "gvdirpart.h"
 
35
#include <src/fileoperation.h>
 
36
#include <src/gvarchive.h>
 
37
#include <src/gvcache.h>
 
38
#include <src/gvdocument.h>
 
39
#include <src/gvfileviewbase.h>
 
40
#include <src/gvfileviewstack.h>
 
41
#include <src/gvprintdialog.h>
 
42
#include <src/gvscrollpixmapview.h>
 
43
#include <src/gvslideshowdialog.h>
 
44
#include <src/gvslideshow.h>
 
45
#include <src/thumbnailloadjob.h>
 
46
 
 
47
#include "config.h"
 
48
 
 
49
// For now let's duplicate
 
50
const char CONFIG_CACHE_GROUP[]="cache";
 
51
const char CONFIG_FILEOPERATION_GROUP[]="file operations";
 
52
const char CONFIG_JPEGTRAN_GROUP[]="jpegtran";
 
53
const char CONFIG_SLIDESHOW_GROUP[]="slide show";
 
54
const char CONFIG_THUMBNAILLOADJOB_GROUP[]="thumbnail loading";
 
55
const char CONFIG_VIEW_GROUP[]="GwenviewPart View";
 
56
 
 
57
 
 
58
class GVDirPartView : public GVScrollPixmapView {
 
59
public:
 
60
        GVDirPartView(QWidget* parent, GVDocument* document, KActionCollection* actionCollection, GVDirPartBrowserExtension* browserExtension)
 
61
        : GVScrollPixmapView(parent, document, actionCollection), mBrowserExtension(browserExtension)
 
62
        {}
 
63
 
 
64
protected:
 
65
        void openContextMenu(const QPoint&) {
 
66
                mBrowserExtension->contextMenu();
 
67
        }
 
68
 
 
69
private:
 
70
        GVDirPartBrowserExtension* mBrowserExtension;
 
71
};
 
72
 
 
73
 
 
74
//Factory Code
 
75
typedef KParts::GenericFactory<GVDirPart> GVDirFactory;
 
76
K_EXPORT_COMPONENT_FACTORY( libgvdirpart /*library name*/, GVDirFactory )
 
77
 
 
78
GVDirPart::GVDirPart(QWidget* parentWidget, const char* /*widgetName*/, QObject* parent, const char* name,
 
79
                     const QStringList &) : KParts::ReadOnlyPart( parent, name )  {
 
80
        setInstance( GVDirFactory::instance() );
 
81
        KGlobal::locale()->insertCatalogue( "gwenview" );
 
82
 
 
83
        mBrowserExtension = new GVDirPartBrowserExtension(this);
 
84
        mBrowserExtension->updateActions();
 
85
 
 
86
        mSplitter = new QSplitter(Qt::Horizontal, parentWidget, "gwenview-kpart-splitter");
 
87
 
 
88
        // Create the widgets
 
89
        mDocument = new GVDocument(this);
 
90
        mFilesView = new GVFileViewStack(mSplitter, actionCollection());
 
91
        mPixmapView = new GVDirPartView(mSplitter, mDocument, actionCollection(), mBrowserExtension);
 
92
 
 
93
        mSlideShow = new GVSlideShow(mDocument);
 
94
 
 
95
        FileOperation::kpartConfig();
 
96
        mFilesView->kpartConfig();
 
97
 
 
98
        setWidget(mSplitter);
 
99
 
 
100
        KStdAction::saveAs( mDocument, SLOT(saveAs()), actionCollection(), "saveAs" );
 
101
        new KAction(i18n("Rotate &Right"), "rotate_cw", CTRL + Key_R, this, SLOT(rotateRight()), actionCollection(), "rotate_right");
 
102
 
 
103
        connect(mFilesView, SIGNAL(urlChanged(const KURL&)),
 
104
                mDocument, SLOT(setURL(const KURL&)) );
 
105
        connect(mFilesView, SIGNAL(directoryChanged(const KURL&)),
 
106
                this, SLOT(directoryChanged(const KURL&)) );
 
107
        connect(mDocument, SIGNAL(loaded(const KURL&)),
 
108
                this, SLOT(loaded(const KURL&)) );
 
109
 
 
110
        QValueList<int> splitterSizes;
 
111
        splitterSizes.append(20);
 
112
        mSplitter->setSizes(splitterSizes);
 
113
 
 
114
        // KIconLoader is weird.  If I preload them here it remembers about them for the following KAction.
 
115
        KIconLoader iconLoader = KIconLoader("gwenview");
 
116
        iconLoader.loadIconSet("slideshow", KIcon::Toolbar);
 
117
 
 
118
        mToggleSlideShow = new KToggleAction(i18n("Slide Show..."), "slideshow", 0, this, SLOT(toggleSlideShow()), actionCollection(), "slideshow");
 
119
 
 
120
        setXMLFile( "gvdirpart/gvdirpart.rc" );
 
121
}
 
122
 
 
123
GVDirPart::~GVDirPart() {
 
124
        delete mSlideShow;
 
125
}
 
126
 
 
127
 
 
128
void GVDirPart::partActivateEvent(KParts::PartActivateEvent* event) {
 
129
        KConfig* config=new KConfig("gwenviewrc");
 
130
        if (event->activated()) {
 
131
                FileOperation::readConfig(config, CONFIG_FILEOPERATION_GROUP);
 
132
                mSlideShow->readConfig(config, CONFIG_SLIDESHOW_GROUP);
 
133
                mPixmapView->readConfig(config, CONFIG_VIEW_GROUP);
 
134
                ThumbnailLoadJob::readConfig(config,CONFIG_THUMBNAILLOADJOB_GROUP);
 
135
                GVCache::instance()->readConfig(config,CONFIG_CACHE_GROUP);
 
136
        } else {
 
137
                mPixmapView->writeConfig(config, CONFIG_VIEW_GROUP);
 
138
        }
 
139
        delete config;
 
140
}
 
141
 
 
142
 
 
143
KAboutData* GVDirPart::createAboutData() {
 
144
        KAboutData* aboutData = new KAboutData( "gvdirpart", I18N_NOOP("GVDirPart"),
 
145
                                                "0.1", I18N_NOOP("Image Browser"),
 
146
                                                KAboutData::License_GPL,
 
147
                                                "(c) 2004, Jonathan Riddell <jr@jriddell.org>");
 
148
        return aboutData;
 
149
}
 
150
 
 
151
bool GVDirPart::openFile() {
 
152
        //unused because openURL implemented
 
153
 
 
154
        //mDocument->setFilename(mFile);
 
155
        return true;
 
156
}
 
157
 
 
158
bool GVDirPart::openURL(const KURL& url) {
 
159
        if (!url.isValid()) {
 
160
                return false;
 
161
        }
 
162
 
 
163
        emit started( 0 );
 
164
        m_url = url;
 
165
        m_url.adjustPath(1);
 
166
 
 
167
        emit setWindowCaption( m_url.prettyURL() );
 
168
        mFilesView->setDirURL(m_url);
 
169
 
 
170
        return true;
 
171
}
 
172
 
 
173
void GVDirPart::loaded(const KURL& url) {
 
174
        QString caption = url.filename();
 
175
        if( !mDocument->image().isNull())
 
176
                caption += QString(" %1 x %2").arg(mDocument->width()).arg(mDocument->height());
 
177
        emit setWindowCaption(caption);
 
178
        emit completed();
 
179
}
 
180
 
 
181
KURL GVDirPart::pixmapURL() {
 
182
        return mDocument->url();
 
183
}
 
184
 
 
185
void GVDirPart::toggleSlideShow() {
 
186
        if (mToggleSlideShow->isChecked()) {
 
187
                GVSlideShowDialog dialog(mSplitter, mSlideShow);
 
188
                if (!dialog.exec()) {
 
189
                        mToggleSlideShow->setChecked(false);
 
190
                        return;
 
191
                }
 
192
        KURL::List list;
 
193
        KFileItemListIterator it( *mFilesView->currentFileView()->items() );
 
194
        for ( ; it.current(); ++it ) {
 
195
            KFileItem* item=it.current();
 
196
            if (!item->isDir() && !GVArchive::fileItemIsArchive(item)) {
 
197
                list.append(item->url());
 
198
            }
 
199
        }
 
200
        if (list.count()==0) {
 
201
                        mToggleSlideShow->setChecked(false);
 
202
            return;
 
203
        }
 
204
                //FIXME turn on full screen here (anyone know how?)
 
205
                mSlideShow->start(list);
 
206
        } else {
 
207
                //FIXME turn off full screen here
 
208
                mSlideShow->stop();
 
209
        }
 
210
}
 
211
 
 
212
void GVDirPart::print() {
 
213
        KPrinter printer;
 
214
        if ( !mDocument->filename().isEmpty() ) {
 
215
                printer.setDocName( m_url.filename() );
 
216
                KPrinter::addDialogPage( new GVPrintDialogPage( mDocument, mPixmapView, "GV page"));
 
217
 
 
218
                if (printer.setup(mPixmapView, QString::null, true)) {
 
219
                        mDocument->print(&printer);
 
220
                }
 
221
        }
 
222
}
 
223
 
 
224
void GVDirPart::rotateRight() {
 
225
        mDocument->transform(GVImageUtils::ROT_90);
 
226
}
 
227
 
 
228
void GVDirPart::directoryChanged(const KURL& dirURL) {
 
229
        if( dirURL == m_url ) return;
 
230
        emit mBrowserExtension->openURLRequest(dirURL);
 
231
}
 
232
 
 
233
/***** GVDirPartBrowserExtension *****/
 
234
 
 
235
GVDirPartBrowserExtension::GVDirPartBrowserExtension(GVDirPart* viewPart, const char* name)
 
236
        :KParts::BrowserExtension(viewPart, name) {
 
237
        mGVDirPart = viewPart;
 
238
        emit enableAction("print", true );
 
239
}
 
240
 
 
241
GVDirPartBrowserExtension::~GVDirPartBrowserExtension() {
 
242
}
 
243
 
 
244
void GVDirPartBrowserExtension::updateActions() {
 
245
        /*
 
246
        emit enableAction( "copy", true );
 
247
        emit enableAction( "cut", true );
 
248
        emit enableAction( "trash", true);
 
249
        emit enableAction( "del", true );
 
250
        emit enableAction( "editMimeType", true );
 
251
        */
 
252
}
 
253
 
 
254
void GVDirPartBrowserExtension::del() {
 
255
        kdDebug() << k_funcinfo << endl;
 
256
}
 
257
 
 
258
void GVDirPartBrowserExtension::trash() {
 
259
        kdDebug() << k_funcinfo << endl;
 
260
}
 
261
 
 
262
void GVDirPartBrowserExtension::editMimeType() {
 
263
        kdDebug() << k_funcinfo << endl;
 
264
}
 
265
 
 
266
void GVDirPartBrowserExtension::refresh() {
 
267
        kdDebug() << k_funcinfo << endl;
 
268
}
 
269
 
 
270
void GVDirPartBrowserExtension::copy() {
 
271
        kdDebug() << k_funcinfo << endl;
 
272
}
 
273
void GVDirPartBrowserExtension::cut() {
 
274
        kdDebug() << k_funcinfo << endl;
 
275
}
 
276
 
 
277
void GVDirPartBrowserExtension::contextMenu() {
 
278
        /*FIXME Why is this KFileMetaInfo invalid?
 
279
        KFileMetaInfo metaInfo = KFileMetaInfo(m_gvImagePart->filePath());
 
280
        kdDebug() << k_funcinfo << "m_gvImagePart->filePath(): " << m_gvImagePart->filePath() << endl;
 
281
        kdDebug() << k_funcinfo << "metaInfo.isValid(): " << metaInfo.isValid() << endl;
 
282
        kdDebug() << k_funcinfo << "above" << endl;
 
283
        QString mimeType = metaInfo.mimeType();
 
284
        kdDebug() << k_funcinfo << "below" << endl;
 
285
        emit popupMenu(QCursor::pos(), m_gvImagePart->url(), mimeType);
 
286
        */
 
287
        emit popupMenu(QCursor::pos(), mGVDirPart->pixmapURL(), 0);
 
288
}
 
289
 
 
290
void GVDirPartBrowserExtension::print() {
 
291
        mGVDirPart->print();
 
292
}
 
293
 
 
294
#include "gvdirpart.moc"