]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinapplication.cpp
Use capitalized KDE includes
[dolphin.git] / src / dolphinapplication.cpp
index cad182d6aee3bb9b0c543d868e2bf197079af38b..13a2b60d8462ed9f9d072cf0c768f3f79406a184 100644 (file)
  *   You should have received a copy of the GNU General Public License     *
  *   along with this program; if not, write to the                         *
  *   Free Software Foundation, Inc.,                                       *
- *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
+ *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
  ***************************************************************************/
 
 #include "dolphinapplication.h"
 #include "dolphinmainwindow.h"
+#include "dolphinviewcontainer.h"
 
-DolphinApplication::DolphinApplication()
+#include <applicationadaptor.h>
+#include <KCmdLineArgs>
+#include <KUrl>
+#include <QtDBus/QDBusConnection>
+
+DolphinApplication::DolphinApplication() :
+    m_lastId(0)
 {
+    new ApplicationAdaptor(this);
+    QDBusConnection::sessionBus().registerObject("/dolphin/Application", this);
 }
 
-/*
- * cleanup what ever is left from the MainWindows
- */
 DolphinApplication::~DolphinApplication()
 {
-    while( m_mainWindows.count() != 0 )
+    // cleanup what ever is left from the MainWindows
+    while (m_mainWindows.count() != 0) {
         delete m_mainWindows.takeFirst();
+    }
 }
 
 DolphinApplication* DolphinApplication::app()
@@ -41,24 +49,63 @@ DolphinApplication* DolphinApplication::app()
 
 DolphinMainWindow* DolphinApplication::createMainWindow()
 {
-    DolphinMainWindow* mainwindow = new DolphinMainWindow;
-    mainwindow->init();
-    
-    m_mainWindows.append( mainwindow );
-    return mainwindow;
+    DolphinMainWindow* mainWindow = new DolphinMainWindow(m_lastId);
+    ++m_lastId;
+    mainWindow->init();
+
+    m_mainWindows.append(mainWindow);
+    return mainWindow;
 }
 
-void DolphinApplication::removeMainWindow( DolphinMainWindow *mainwindow )
+void DolphinApplication::removeMainWindow(DolphinMainWindow* mainWindow)
 {
-    m_mainWindows.removeAll( mainwindow );
+    m_mainWindows.removeAll(mainWindow);
 }
 
 void DolphinApplication::refreshMainWindows()
 {
-    for( int i = 0; i < m_mainWindows.count(); ++i ) {
+    for (int i = 0; i < m_mainWindows.count(); ++i) {
         m_mainWindows[i]->refreshViews();
     }
 }
 
-#include "dolphinapplication.moc"
+int DolphinApplication::newInstance()
+{
+    KCmdLineArgs* args = KCmdLineArgs::parsedArgs();
+    static bool first = true;
+
+    const int argsCount = args->count();
+    if ((argsCount > 0) || !first || !isSessionRestored()) {
+        QList<KUrl> urls;
+        for (int i = 0; i < argsCount; ++i) {
+            urls.append(args->url(i));
+        }
+
+        DolphinMainWindow* win = createMainWindow();
+        if (urls.count() > 0) {
+            if (args->isSet("select")) {
+                win->openFiles(urls);
+            } else {
+                win->openDirectories(urls);
+            }
+        }
+        win->show();
+    }
 
+    first = false;
+    args->clear();
+    return 0;
+}
+
+int DolphinApplication::openWindow(const QString& urlString)
+{
+    DolphinMainWindow* win = createMainWindow();
+    const KUrl url(urlString);
+    if (!url.isEmpty()) {
+        win->openDirectories(QList<KUrl>() << url);
+    }
+    win->show();
+    return win->getId();
+}
+
+#include "dolphinapplication.moc"