(for review)
Native "Open With" dialog on Windows (by default).
This allows to use (and associate) given file extensions with any Windows application directly, as users expect.

- moved KRun::KRunPrivate declaration to krun_p.h
- added KRun::KRunPrivate::displayNativeOpenWithDialog() for Windows only
  in krun_win.cpp
- added a note to KOpenWithDialog that using KRun::displayOpenWithDialog()
  is recommended

Also reported in http://intevation.de/roundup/kolab/issue2766

--
regards / pozdrawiam, Jaroslaw Staniek
 Sponsored by OpenOffice Polska (http://www.openoffice.com.pl/en) to work on
 Kexi & KOffice (http://www.kexi.pl/en, http://www.koffice.org/kexi)
 KDE Libraries for MS Windows (http://windows.kde.org)
Index: kio/kio/krun.cpp
===================================================================
--- kio/kio/krun.cpp    (wersja 830359)
+++ kio/kio/krun.cpp    (kopia robocza)
@@ -31,7 +31,6 @@
 #include <sys/stat.h>
 
 #include <QtGui/QWidget>
-#include <QtCore/QPointer>
 
 #include "kmimetypetrader.h"
 #include "kmimetype.h"
@@ -71,61 +70,19 @@
 #include <kwindowsystem.h>
 #endif
 
-class KRun::KRunPrivate
+KRun::KRunPrivate::KRunPrivate(KRun *parent)
+  : q(parent),
+    m_showingDialog(false)
 {
-public:
-    KRunPrivate(KRun *parent)
-      : q(parent),
-        m_showingDialog(false)
-    {
-    }
+}
 
-    void init (const KUrl& url, QWidget* window, mode_t mode,
-               bool isLocalFile, bool showProgressInfo, const QByteArray& asn);
+void KRun::KRunPrivate::startTimer()
+{
+    m_timer.start(0);
+}
 
-    // This helper method makes debugging easier: a single breakpoint for all
-    // the code paths that start the timer - at least from KRun itself.
-    // TODO: add public method startTimer() and deprecate timer() accessor,
-    // starting is the only valid use of the timer in subclasses (BrowserRun, 
KHTMLRun and KonqRun)
-    void startTimer() {
-        m_timer.start(0);
-    }
+// ---------------------------------------------------------------------------
 
-    KRun *q;
-    bool m_showingDialog;
-    bool m_runExecutables;
-
-    QString m_preferredService;
-    QString m_externalBrowser;
-    QString m_localPath;
-    QString m_suggestedFileName;
-    QPointer <QWidget> m_window;
-    QByteArray m_asn;
-    KUrl m_strURL;
-    bool m_bFault;
-    bool m_bAutoDelete;
-    bool m_bProgressInfo;
-    bool m_bFinished;
-    KIO::Job * m_job;
-    QTimer m_timer;
-
-    /**
-     * Used to indicate that the next action is to scan the file.
-     * This action is invoked from slotTimeout.
-     */
-    bool m_bScanFile;
-    bool m_bIsDirectory;
-
-    /**
-     * Used to indicate that the next action is to initialize.
-     * This action is invoked from slotTimeout
-     */
-    bool m_bInit;
-
-    bool m_bIsLocalFile;
-    mode_t m_mode;
-};
-
 bool KRun::isExecutableFile( const KUrl& url, const QString &mimetype )
 {
   if ( !url.isLocalFile() )
@@ -211,15 +168,24 @@
   return KRun::run( *offer, lst, window, tempFile, suggestedFileName, asn );
 }
 
-bool KRun::displayOpenWithDialog( const KUrl::List& lst, QWidget* window, bool 
tempFiles, const QString& suggestedFileName,
-    const QByteArray& asn )
+bool KRun::displayOpenWithDialog( const KUrl::List& lst, QWidget* window, bool 
tempFiles, 
+                                  const QString& suggestedFileName, const 
QByteArray& asn )
 {
     if (!KAuthorized::authorizeKAction("openwith"))
     {
-       KMessageBox::sorry(window, i18n("You are not authorized to select an 
application to open this file."));
+       KMessageBox::sorry(window, 
+         i18n("You are not authorized to select an application to open this 
file."));
        return false;
     }
 
+#ifdef Q_WS_WIN
+    KConfigGroup cfgGroup(KGlobal::config(), "KOpenWithDialog Settings");
+    if (cfgGroup.readEntry("Native", true))
+    {
+      return KRun::KRunPrivate::displayOpenWithDialog( lst, window, tempFiles,
+                                                       suggestedFileName, asn 
);
+    }
+#endif
     KOpenWithDialog l( lst, i18n("Open with:"), QString(), window );
     if ( l.exec() )
     {
Index: kio/kio/krun_p.h
===================================================================
--- kio/kio/krun_p.h    (wersja 830359)
+++ kio/kio/krun_p.h    (kopia robocza)
@@ -23,6 +23,8 @@
 #define KRUN_P_H
 
 #include <QtCore/QObject>
+#include <QtCore/QPointer>
+
 #include "kprocess.h"
 #include "kstartupinfo.h"
 
@@ -66,4 +68,59 @@
     Q_DISABLE_COPY(KProcessRunner)
 };
 
+/**
+ * @internal
+ */
+class KRun::KRunPrivate
+{
+public:
+    KRunPrivate(KRun *parent);
+
+    void init (const KUrl& url, QWidget* window, mode_t mode,
+               bool isLocalFile, bool showProgressInfo, const QByteArray& asn);
+
+    // This helper method makes debugging easier: a single breakpoint for all
+    // the code paths that start the timer - at least from KRun itself.
+    // TODO: add public method startTimer() and deprecate timer() accessor,
+    // starting is the only valid use of the timer in subclasses (BrowserRun, 
KHTMLRun and KonqRun)
+    void startTimer();
+
+    static bool displayOpenWithDialog( const KUrl::List& lst, QWidget* window, 
bool tempFiles,
+                                       const QString& suggestedFileName, const 
QByteArray& asn );
+
+    KRun *q;
+    bool m_showingDialog;
+    bool m_runExecutables;
+
+    QString m_preferredService;
+    QString m_externalBrowser;
+    QString m_localPath;
+    QString m_suggestedFileName;
+    QPointer <QWidget> m_window;
+    QByteArray m_asn;
+    KUrl m_strURL;
+    bool m_bFault;
+    bool m_bAutoDelete;
+    bool m_bProgressInfo;
+    bool m_bFinished;
+    KIO::Job * m_job;
+    QTimer m_timer;
+
+    /**
+     * Used to indicate that the next action is to scan the file.
+     * This action is invoked from slotTimeout.
+     */
+    bool m_bScanFile;
+    bool m_bIsDirectory;
+
+    /**
+     * Used to indicate that the next action is to initialize.
+     * This action is invoked from slotTimeout
+     */
+    bool m_bInit;
+
+    bool m_bIsLocalFile;
+    mode_t m_mode;
+};
+
 #endif  // KRUN_P_H
Index: kio/kfile/kopenwithdialog.h
===================================================================
--- kio/kfile/kopenwithdialog.h (wersja 830359)
+++ kio/kfile/kopenwithdialog.h (kopia robocza)
@@ -29,8 +29,11 @@
 class KOpenWithDialogPrivate;
 
 /**
- * "Open with" dialog box.
+ * "Open With" dialog box.
  *
+ * @note It is recommended to use KRun::displayOpenWithDialog() instead, 
because it is simpler
+ *       and on Windows it gives native "Open With" dialog box (by default).
+ *
  * @author David Faure <[EMAIL PROTECTED]>
  */
 class KIO_EXPORT KOpenWithDialog : public KDialog
Index: kio/CMakeLists.txt
===================================================================
--- kio/CMakeLists.txt  (wersja 830359)
+++ kio/CMakeLists.txt  (kopia robocza)
@@ -128,6 +128,12 @@
    )
 endif(UNIX)
 
+if(WIN32)
+   set(kiocore_STAT_SRCS ${kiocore_STAT_SRCS}
+       kio/krun_win.cpp
+   )
+endif(WIN32)
+
 set(kbookmarks_STAT_SRCS
   bookmarks/kbookmark.cc
   bookmarks/kbookmarkimporter.cc
/* This file is part of the KDE libraries
    Copyright (C) 2008 Jaroslaw Staniek <[EMAIL PROTECTED]>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library 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
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
    Boston, MA 02110-1301, USA.
*/

#include "krun.h"
#include "krun_p.h"

#include <QDir>
#include <QFile>
#include <QWidget>

#include <windows.h>

// TODO move to a shared lib
static int runDll(WId windowId, const QString& libraryName, const QString& functionName, 
            const QString& arguments = QString())
{
  HMODULE libHandle = LoadLibraryA( QFile::encodeName(libraryName).constData() );
  if (!libHandle)
    return false;
  typedef int (WINAPI *FunctionType)(HWND, HMODULE, LPCSTR, int);
  FunctionType function 
    = (FunctionType)GetProcAddress( libHandle, functionName.toLatin1().constData() );
  if (!function)
    return false;
  int result = function((HWND)windowId, libHandle, (LPCSTR)arguments.toLatin1().constData(), SW_SHOW);
  FreeLibrary(libHandle);
  return result;
}

// TODO move to a shared lib
static int runDll(QWidget* parent, const QString& libraryName, const QString& functionName, 
            const QString& arguments = QString())
{
  return runDll(parent ? parent->winId() : 0, libraryName, functionName, arguments);
}


// Windows implementation using "OpenAs_RunDLL" entry
bool KRun::KRunPrivate::displayNativeOpenWithDialog( const KUrl::List& lst, QWidget* window, bool tempFiles,
                                               const QString& suggestedFileName, const QByteArray& asn )
{
    Q_UNUSED(tempFiles);
    Q_UNUSED(suggestedFileName);
    Q_UNUSED(asn);

    QStringList fnames;
    foreach( const KUrl& url, lst )
    {
      fnames += QFile::encodeName( 
        QDir::toNativeSeparators( url.path() ) ); // QFile::encodeName() needed because we will use toLatin1()
    }
    int result = runDll( window, QLatin1String("shell32.dll"), QLatin1String("OpenAs_RunDLL"), 
                         QFile::encodeName( fnames.join(" ") ) );
    return result == 0;
}
_______________________________________________
Kde-windows mailing list
[email protected]
https://mail.kde.org/mailman/listinfo/kde-windows

Reply via email to