1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-11 01:22:10 +01:00

Command line option to open url in current tab.

-ct=URL or --current-tab=URL
This commit is contained in:
nowrep 2012-04-03 20:41:07 +02:00
parent 7c7c1787bc
commit 79a548b365
3 changed files with 28 additions and 3 deletions

View File

@ -50,6 +50,7 @@ void CommandLineOptions::showHelp()
" -nw or --new-window open new window\n"
" -pb or --private-browsing start private browsing\n"
" -dm or --download-manager show download manager\n"
" -ct=URL or --current-tab=URL open URL in current tab\n"
"\n"
" QupZilla is a new, fast and secure web browser\n"
" based on WebKit core (http://webkit.org) and\n"
@ -147,6 +148,15 @@ void CommandLineOptions::parseActions()
pair.text = "";
m_actions.append(pair);
}
if (arg.startsWith("-ct") || arg.startsWith("--current-tab")) {
arg.remove("-ct=");
arg.remove("--current-tab=");
ActionPair pair;
pair.action = Qz::CL_OpenUrlInCurrentTab;
pair.text = arg;
m_actions.append(pair);
}
}
const QString &url = arguments.last();

View File

@ -158,6 +158,11 @@ MainApplication::MainApplication(int &argc, char** argv)
messages.append("ACTION:StartPrivateBrowsing");
m_postLaunchActions.append(PrivateBrowsing);
break;
case Qz::CL_OpenUrlInCurrentTab:
startUrl = QUrl::fromUserInput(pair.text);
messages.append("ACTION:OpenUrlInCurrentTab" + pair.text);
m_postLaunchActions.append(PrivateBrowsing);
break;
case Qz::CL_OpenUrl:
startUrl = QUrl::fromUserInput(pair.text);
messages.append("URL:" + pair.text);
@ -448,6 +453,8 @@ void MainApplication::sendMessages(Qz::AppMessageType mes, bool state)
void MainApplication::receiveAppMessage(QString message)
{
QWidget* actWin = getWindow();
QUrl actUrl;
if (message.startsWith("URL:")) {
QUrl url = QUrl::fromUserInput(message.mid(4));
addNewTab(url);
@ -457,7 +464,6 @@ void MainApplication::receiveAppMessage(QString message)
QString text = message.mid(7);
if (text == "NewTab") {
addNewTab();
actWin = getWindow();
}
else if (text == "NewWindow") {
actWin = makeNewWindow(Qz::BW_NewWindow);
@ -468,19 +474,27 @@ void MainApplication::receiveAppMessage(QString message)
}
else if (text == "StartPrivateBrowsing") {
sendMessages(Qz::AM_StartPrivateBrowsing, true);
actWin = getWindow();
}
else if (text.startsWith("OpenUrlInCurrentTab")) {
actUrl = QUrl::fromUserInput(text.remove("OpenUrlInCurrentTab"));
}
}
if (!actWin && !isClosing()) { // It can only occur if download manager window was still open
makeNewWindow(Qz::BW_NewWindow);
makeNewWindow(Qz::BW_NewWindow, actUrl);
return;
}
QupZilla* qz = qobject_cast<QupZilla*>(actWin);
actWin->setWindowState(actWin->windowState() & ~Qt::WindowMinimized);
actWin->raise();
actWin->activateWindow();
actWin->setFocus();
if (qz && !actUrl.isEmpty()) {
qz->loadAddress(actUrl);
}
}
void MainApplication::addNewTab(const QUrl &url)

View File

@ -47,6 +47,7 @@ enum BrowserWindow {
enum CommandLineAction {
CL_NoAction,
CL_OpenUrl,
CL_OpenUrlInCurrentTab,
CL_StartWithProfile,
CL_StartWithoutAddons,
CL_NewTab,