summaryrefslogtreecommitdiff
path: root/src/application.cpp
diff options
context:
space:
mode:
authorAndrea Diamantini <adjam7@gmail.com>2009-02-16 00:06:28 +0100
committerAndrea Diamantini <adjam7@gmail.com>2009-02-16 00:06:28 +0100
commit4150695c5fff0504cf19ad74b3f185bd67397497 (patch)
tree9cf5744503e83c3deea72820cd26cdd4d39fde0b /src/application.cpp
parentModified adjam's mail (diff)
downloadrekonq-4150695c5fff0504cf19ad74b3f185bd67397497.tar.xz
new singleton Application class.
Try 1..
Diffstat (limited to 'src/application.cpp')
-rw-r--r--src/application.cpp296
1 files changed, 115 insertions, 181 deletions
diff --git a/src/application.cpp b/src/application.cpp
index 40addcac..d6679b97 100644
--- a/src/application.cpp
+++ b/src/application.cpp
@@ -18,11 +18,14 @@
 * ============================================================ */
-// Local Includes
+// Self Includes
#include "application.h"
+#include "application.moc"
+// Auto Includes
#include "rekonq.h"
+// Local Includes
#include "mainwindow.h"
#include "cookiejar.h"
#include "history.h"
@@ -56,46 +59,48 @@ HistoryManager *Application::s_historyManager = 0;
NetworkAccessManager *Application::s_networkAccessManager = 0;
-
-Application::Application(KCmdLineArgs *args, const QString &serverName)
- : KApplication()
- , m_localServer(0)
+Application::Application()
+ : KUniqueApplication()
+// , m_localServer(0)
{
- QLocalSocket socket;
- socket.connectToServer(serverName);
- if (socket.waitForConnected(500))
- {
- QTextStream stream(&socket);
- int n = args->count();
- if (n > 1)
- stream << args->arg(n-1);
- else
- stream << QString();
- stream.flush();
- socket.waitForBytesWritten();
- return;
- }
-
- KApplication::setQuitOnLastWindowClosed(true);
-
- m_localServer = new QLocalServer(this);
- connect(m_localServer, SIGNAL(newConnection()), this, SLOT(newLocalSocketConnection()));
- if (!m_localServer->listen(serverName))
- {
- if (m_localServer->serverError() == QAbstractSocket::AddressInUseError
- && QFile::exists(m_localServer->serverName()))
- {
- QFile::remove(m_localServer->serverName());
- m_localServer->listen(serverName);
- }
- }
-
- QDesktopServices::setUrlHandler(QLatin1String("http"), this, "openUrl");
- QString localSysName = QLocale::system().name();
-
- KConfig config("rekonqrc");
- KConfigGroup group = config.group("sessions");
- m_lastSession = group.readEntry( QString("lastSession"), QByteArray() );
+ m_mainWindow = new MainWindow();
+ m_mainWindow->show();
+
+// QLocalSocket socket;
+// socket.connectToServer(serverName);
+// if (socket.waitForConnected(500))
+// {
+// QTextStream stream(&socket);
+// int n = args->count();
+// if (n > 1)
+// stream << args->arg(n-1);
+// else
+// stream << QString();
+// stream.flush();
+// socket.waitForBytesWritten();
+// return;
+// }
+//
+// KApplication::setQuitOnLastWindowClosed(true);
+//
+// m_localServer = new QLocalServer(this);
+// connect(m_localServer, SIGNAL(newConnection()), this, SLOT(newLocalSocketConnection()));
+// if (!m_localServer->listen(serverName))
+// {
+// if (m_localServer->serverError() == QAbstractSocket::AddressInUseError
+// && QFile::exists(m_localServer->serverName()))
+// {
+// QFile::remove(m_localServer->serverName());
+// m_localServer->listen(serverName);
+// }
+// }
+//
+// QDesktopServices::setUrlHandler(QLatin1String("http"), this, "openUrl");
+// QString localSysName = QLocale::system().name();
+//
+// KConfig config("rekonqrc");
+// KConfigGroup group = config.group("sessions");
+// m_lastSession = group.readEntry( QString("lastSession"), QByteArray() );
setWindowIcon( KIcon("rekonq") );
@@ -105,147 +110,85 @@ Application::Application(KCmdLineArgs *args, const QString &serverName)
Application::~Application()
{
- qDeleteAll(m_mainWindows);
delete s_networkAccessManager;
}
-Application *Application::instance()
-{
- return (static_cast<Application *>(QCoreApplication::instance()));
-}
-
-
-/*!
- Any actions that can be delayed until the window is visible
- */
-void Application::postLaunch()
+int Application::newInstance()
{
- QString directory = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
- if ( directory.isEmpty() )
- {
- directory = QDir::homePath() + QLatin1String("/.") + QCoreApplication::applicationName();
- }
- QWebSettings::setIconDatabasePath(directory);
-
- // newMainWindow() needs to be called in main() for this to happen
- if (m_mainWindows.count() > 0)
+ KCmdLineArgs::setCwd(QDir::currentPath().toUtf8());
+ KCmdLineArgs* args = KCmdLineArgs::parsedArgs();
+ static bool first = true;
+ if (args->count() > 0)
{
- KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
- int n = args->count();
- if (n > 1)
+ for (int i = 0; i < args->count(); ++i)
{
- KUrl url = MainWindow::guessUrlFromString( args->arg(n-1) );
+ KUrl url = MainWindow::guessUrlFromString( args->arg(i) );
+ newTab();
mainWindow()->loadUrl( url );
}
- else
+ }
+ else
+ {
+ if( !first || !isSessionRestored())
{
+ newTab();
mainWindow()->slotHome();
}
}
- Application::historyManager();
-}
-
-
-void Application::downloadUrl(const KUrl &srcUrl, const KUrl &destUrl)
-{
- new Download( srcUrl, destUrl );
-}
-
-
-QList<MainWindow*> Application::mainWindows()
-{
- clean();
- QList<MainWindow*> list;
- for (int i = 0; i < m_mainWindows.count(); ++i)
- {
- list.append(m_mainWindows.at(i));
- }
- return list;
+ first = false;
+ args->clear();
+ return 0;
}
-void Application::clean()
+Application *Application::instance()
{
- // cleanup any deleted main windows first
- for (int i = m_mainWindows.count() - 1; i >= 0; --i)
- {
- if (m_mainWindows.at(i).isNull())
- {
- m_mainWindows.removeAt(i);
- }
- }
+ return (static_cast<Application *>(QCoreApplication::instance()));
}
-void Application::saveSession()
+void Application::postLaunch()
{
- QWebSettings *globalSettings = QWebSettings::globalSettings();
- if ( globalSettings->testAttribute( QWebSettings::PrivateBrowsingEnabled ) )
- return;
-
- clean();
-
- KConfig config("rekonqrc");
- KConfigGroup group = config.group("sessions");
- QByteArray data;
- QBuffer buffer(&data);
- QDataStream stream(&buffer);
- buffer.open(QIODevice::ReadWrite);
-
- stream << m_mainWindows.count();
- for (int i = 0; i < m_mainWindows.count(); ++i)
+ // set Icon Database Path to store "favicons" associated with web sites
+ QString directory = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
+ if ( directory.isEmpty() )
{
- stream << m_mainWindows.at(i)->saveState();
+ directory = QDir::homePath() + QLatin1String("/.") + QCoreApplication::applicationName();
}
-
- group.writeEntry( QString("lastSession"), data );
-}
-
+ QWebSettings::setIconDatabasePath(directory);
-bool Application::canRestoreSession() const
-{
- return !m_lastSession.isEmpty();
+ Application::historyManager();
}
-void Application::restoreLastSession()
+void Application::downloadUrl(const KUrl &srcUrl, const KUrl &destUrl)
{
- QList<QByteArray> windows;
- QBuffer buffer(&m_lastSession);
- QDataStream stream(&buffer);
- buffer.open(QIODevice::ReadOnly);
- int windowCount;
- stream >> windowCount;
- for (int i = 0; i < windowCount; ++i)
- {
- QByteArray windowState;
- stream >> windowState;
- windows.append(windowState);
- }
- for (int i = 0; i < windows.count(); ++i)
- {
- MainWindow *newWindow = 0;
- if (m_mainWindows.count() == 1
- && mainWindow()->tabWidget()->count() == 1
- && mainWindow()->currentTab()->url() == KUrl())
- {
- newWindow = mainWindow();
- }
- else
- {
- newWindow = newMainWindow();
- }
- newWindow->restoreState(windows.at(i));
- }
+ new Download( srcUrl, destUrl );
}
-
-bool Application::isTheOnlyBrowser() const
-{
- return (m_localServer != 0);
-}
+// void Application::saveSession()
+// {
+// QWebSettings *globalSettings = QWebSettings::globalSettings();
+// if ( globalSettings->testAttribute( QWebSettings::PrivateBrowsingEnabled ) )
+// return;
+//
+// KConfig config("rekonqrc");
+// KConfigGroup group = config.group("sessions");
+// QByteArray data;
+// QBuffer buffer(&data);
+// QDataStream stream(&buffer);
+// buffer.open(QIODevice::ReadWrite);
+//
+// stream << m_mainWindows.count();
+// for (int i = 0; i < m_mainWindows.count(); ++i)
+// {
+// stream << m_mainWindows.at(i)->saveState();
+// }
+//
+// group.writeEntry( QString("lastSession"), data );
+// }
void Application::openUrl(const KUrl &url)
@@ -254,43 +197,36 @@ void Application::openUrl(const KUrl &url)
}
-
-MainWindow *Application::newMainWindow()
+MainWindow *Application::mainWindow()
{
- MainWindow *browser = new MainWindow();
- m_mainWindows.prepend(browser);
- browser->show();
- return browser;
+ return m_mainWindow;
}
-MainWindow *Application::mainWindow()
+WebView *Application::newTab()
{
- clean();
- if (m_mainWindows.isEmpty())
- newMainWindow();
- return m_mainWindows[0];
+ return m_mainWindow->tabWidget()->newTab();
}
-void Application::newLocalSocketConnection()
-{
- QLocalSocket *socket = m_localServer->nextPendingConnection();
- if (!socket)
- return;
- socket->waitForReadyRead(1000);
- QTextStream stream(socket);
- QString url;
- stream >> url;
- if (!url.isEmpty())
- {
- mainWindow()->tabWidget()->newTab();
- openUrl(url);
- }
- delete socket;
- mainWindow()->raise();
- mainWindow()->activateWindow();
-}
+// void Application::newLocalSocketConnection()
+// {
+// QLocalSocket *socket = m_localServer->nextPendingConnection();
+// if (!socket)
+// return;
+// socket->waitForReadyRead(1000);
+// QTextStream stream(socket);
+// QString url;
+// stream >> url;
+// if (!url.isEmpty())
+// {
+// mainWindow()->tabWidget()->newTab();
+// openUrl(url);
+// }
+// delete socket;
+// mainWindow()->raise();
+// mainWindow()->activateWindow();
+// }
@@ -323,8 +259,6 @@ HistoryManager *Application::historyManager()
}
-
-
KIcon Application::icon(const KUrl &url) const
{
KIcon icon = KIcon( QWebSettings::iconForUrl(url) );