[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: playground/graphics/gwenview/app
From: Aurélien Gâteau <aurelien.gateau () free ! fr>
Date: 2007-02-24 21:31:26
Message-ID: 1172352686.310303.26160.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 636963 by gateau:
Parse command line and switch mode on start.
M +23 -5 main.cpp
M +43 -16 mainwindow.cpp
M +1 -2 mainwindow.h
--- trunk/playground/graphics/gwenview/app/main.cpp #636962:636963
@@ -1,6 +1,6 @@
/*
Gwenview: an image viewer
-Copyright 2007 Aurélien Gâteau
+Copyright 2007 Aurélien Gâteau
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -18,26 +18,44 @@
*/
// Qt
+#include <QDir>
#include <QString>
// KDE
-#include <KApplication>
-#include <KAboutData>
-#include <KMessageBox>
-#include <KCmdLineArgs>
+#include <kaboutdata.h>
+#include <kapplication.h>
+#include <kcmdlineargs.h>
+#include <klocale.h>
+#include <kmessagebox.h>
// Local
#include "mainwindow.h"
+static KCmdLineOptions options[] = {
+ { "+[file or folder]", I18N_NOOP("A starting file or folder"), 0 },
+ KCmdLineLastOption
+};
+
int main(int argc, char *argv[]) {
KAboutData aboutData( "gwenview", "Gwenview",
"2.0", "An Image Viewer",
KAboutData::License_GPL, "(c) 2007" );
KCmdLineArgs::init( argc, argv, &aboutData );
+ KCmdLineArgs::addCmdLineOptions( options );
+
KApplication app;
Gwenview::MainWindow* window = new Gwenview::MainWindow();
+ KUrl url;
+ KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
+ if (args->count()>0) {
+ url=args->url(0);
+ } else {
+ url.setPath( QDir::currentPath() );
+ }
+
window->show();
+ window->openUrl(url);
return app.exec();
}
--- trunk/playground/graphics/gwenview/app/mainwindow.cpp #636962:636963
@@ -20,7 +20,6 @@
#include "mainwindow.moc"
// Qt
-#include <QDir>
#include <QFrame>
#include <QGridLayout>
#include <QLabel>
@@ -32,8 +31,10 @@
// KDE
#include <kactioncollection.h>
#include <kaction.h>
+#include <kde_file.h>
#include <kdirlister.h>
#include <kfileitem.h>
+#include <kio/netaccess.h>
#include <klocale.h>
#include <kmimetype.h>
#include <kparts/componentfactory.h>
@@ -57,6 +58,25 @@
#define LOG(x) ;
#endif
+static bool urlIsDirectory(QWidget* parent, const KUrl& url) {
+ if( url.fileName(KUrl::ObeyTrailingSlash).isEmpty()) {
+ return true; // file:/somewhere/<nothing here>
+ }
+
+ // Do direct stat instead of using KIO if the file is local (faster)
+ if( url.isLocalFile() && !KIO::probably_slow_mounted( url.path())) {
+ KDE_struct_stat buff;
+ if ( KDE_stat( QFile::encodeName(url.path()), &buff ) == 0 ) {
+ return S_ISDIR( buff.st_mode );
+ }
+ }
+ KIO::UDSEntry entry;
+ if( KIO::NetAccess::stat( url, entry, parent)) {
+ return entry.isDir();
+ }
+ return false;
+}
+
struct MainWindow::Private {
MainWindow* mWindow;
QWidget* mDocumentView;
@@ -203,6 +223,17 @@
mPartLibrary = library;
}
+
+ void initDirModel() {
+ KDirLister* dirLister = mDirModel->dirLister();
+ QStringList mimeTypes;
+ mimeTypes += MimeTypeUtils::dirMimeTypes();
+ mimeTypes += MimeTypeUtils::imageMimeTypes();
+ mimeTypes += MimeTypeUtils::videoMimeTypes();
+ dirLister->setMimeFilter(mimeTypes);
+ }
+
+
};
@@ -213,13 +244,23 @@
d->mWindow = this;
d->mDirModel = new SortedDirModel(this);
d->mPart = 0;
+ d->initDirModel();
d->setupWidgets();
d->setupActions();
- QTimer::singleShot(0, this, SLOT(initDirModel()) );
+
createShellGUI();
}
+void MainWindow::openUrl(const KUrl& url) {
+ if (urlIsDirectory(this, url)) {
+ openDirUrl(url);
+ } else {
+ openDocumentUrl(url);
+ }
+}
+
+
void MainWindow::setActiveViewModeAction(QAction* action) {
bool showDocument, showThumbnail;
if (action == d->mThumbsOnlyAction) {
@@ -238,20 +279,6 @@
}
-void MainWindow::initDirModel() {
- KDirLister* dirLister = d->mDirModel->dirLister();
- QStringList mimeTypes;
- mimeTypes += MimeTypeUtils::dirMimeTypes();
- mimeTypes += MimeTypeUtils::imageMimeTypes();
- mimeTypes += MimeTypeUtils::videoMimeTypes();
- dirLister->setMimeFilter(mimeTypes);
-
- KUrl url;
- url.setPath(QDir::currentPath());
- openDirUrl(url);
-}
-
-
void MainWindow::openDirUrlFromIndex(const QModelIndex& index) {
if (!index.isValid()) {
return;
--- trunk/playground/graphics/gwenview/app/mainwindow.h #636962:636963
@@ -38,6 +38,7 @@
Q_OBJECT
public:
MainWindow();
+ void openUrl(const KUrl&);
protected:
virtual void slotSetStatusBarText(const QString&);
@@ -52,8 +53,6 @@
void openDocumentUrlFromIndex(const QModelIndex&);
void goUp();
- void initDirModel();
-
private:
class Private;
std::auto_ptr<Private> d;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic