Skip to content

Commit

Permalink
Add arora:// URLs
Browse files Browse the repository at this point in the history
Arora URLs replace all "aroramessage://" and "qrc:/" URLs
Arora URLs don't contain the ".html" extension, for example
qrc:/startpage.html -> arora://startpage
  • Loading branch information
AaronDewes committed Aug 28, 2020
1 parent 552331c commit 709ff2f
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 34 deletions.
75 changes: 43 additions & 32 deletions src/browserapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ void BrowserApplication::messageReceived(QLocalSocket *socket)
return;

// Got a normal url
if (!message.startsWith(QLatin1String("aroramessage://"))) {
if (!message.startsWith(QLatin1String("arora://"))) {
QSettings settings;
settings.beginGroup(QLatin1String("tabs"));
TabWidget::OpenUrlIn tab = TabWidget::OpenUrlIn(settings.value(QLatin1String("openLinksFromAppsIn"), TabWidget::NewSelectedTab).toInt());
Expand All @@ -234,37 +234,48 @@ void BrowserApplication::messageReceived(QLocalSocket *socket)
}
mainWindow()->tabWidget()->loadString(message, tab);
return;
}

if (message.startsWith(QLatin1String("aroramessage://getwinid"))) {
#ifdef Q_OS_WIN
QString winid = QString(QLatin1String("%1")).arg((qlonglong)mainWindow()->winId());
#else
mainWindow()->show();
mainWindow()->setFocus();
mainWindow()->raise();
mainWindow()->activateWindow();
alert(mainWindow());
QString winid;
#endif
#ifdef BROWSERAPPLICATION_DEBUG
qDebug() << "BrowserApplication::" << __FUNCTION__ << "sending win id" << winid << mainWindow()->winId();
#endif
QString message = QLatin1String("aroramessage://winid/") + winid;
socket->write(message.toUtf8());
socket->waitForBytesWritten();
return;
}

if (message.startsWith(QLatin1String("aroramessage://winid"))) {
QString winid = message.mid(21);
#ifdef BROWSERAPPLICATION_DEBUG
qDebug() << "BrowserApplication::" << __FUNCTION__ << "got win id:" << winid;
#endif
#ifdef Q_OS_WIN
WId wid = (WId)winid.toLongLong();
SetForegroundWindow(wid);
#endif
} else {
if (message.startsWith(QLatin1String("arora://getwinid"))) {
#ifdef Q_OS_WIN
QString winid = QString(QLatin1String("%1")).arg((qlonglong)mainWindow()->winId());
#else
mainWindow()->show();
mainWindow()->setFocus();
mainWindow()->raise();
mainWindow()->activateWindow();
alert(mainWindow());
QString winid;
#endif
#ifdef BROWSERAPPLICATION_DEBUG
qDebug() << "BrowserApplication::" << __FUNCTION__ << "sending win id" << winid << mainWindow()->winId();
#endif
QString message = QLatin1String("arora://winid/") + winid;
socket->write(message.toUtf8());
socket->waitForBytesWritten();
return;
}

if (message.startsWith(QLatin1String("arora://winid"))) {
QString winid = message.mid(21);
#ifdef BROWSERAPPLICATION_DEBUG
qDebug() << "BrowserApplication::" << __FUNCTION__ << "got win id:" << winid;
#endif
#ifdef Q_OS_WIN
WId wid = (WId)winid.toLongLong();
SetForegroundWindow(wid);
#endif
return;
}
QSettings settings;
settings.beginGroup(QLatin1String("tabs"));
TabWidget::OpenUrlIn tab = TabWidget::OpenUrlIn(settings.value(QLatin1String("openLinksFromAppsIn"), TabWidget::NewSelectedTab).toInt());
settings.endGroup();
if (QUrl(message) == m_lastAskedUrl
&& m_lastAskedUrlDateTime.addSecs(10) > QDateTime::currentDateTime()) {
qWarning() << "Possible recursive openUrl called, ignoring url:" << m_lastAskedUrl;
return;
}
mainWindow()->tabWidget()->loadString(message, tab);
return;
}
}
Expand Down
14 changes: 13 additions & 1 deletion src/locationbar/locationbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,19 @@ void LocationBar::webViewUrlChanged(const QUrl &url)
{
if (hasFocus())
return;
setText(QString::fromUtf8(url.toEncoded()));
if(!url.toString().startsWith(QString("qrc:/"))) {
setText(QString::fromUtf8(url.toEncoded()));
} else {
QUrl newurl = QUrl(url.toString());
QString url_tmp = newurl.toString().mid(5);
newurl = QUrl(QLatin1String("arora://") + url_tmp);
QString urlstr = newurl.toString();
if(urlstr.endsWith(QLatin1String(".html"))) {
urlstr.chop(5);
newurl = QUrl(urlstr);
}
setText(QString::fromUtf8(newurl.toEncoded()));
}
setCursorPosition(0);
}

Expand Down
12 changes: 11 additions & 1 deletion src/webview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,17 @@ void WebView::loadUrl(const QUrl &url, const QString &title)
emit titleChanged(tr("Loading..."));
else
emit titleChanged(title);
load(url);
QUrl oldurl = QUrl(url.toString());
QUrl newurl = QUrl(url.toString());
if(newurl.toString().startsWith(QLatin1String("arora://"))) {
QString url_tmp = newurl.toString().mid(8);
newurl = QUrl(QLatin1String("qrc:/") + url_tmp);
QString urlstr = newurl.toString();
if(!urlstr.endsWith(QLatin1String(".html"))) {
newurl = QUrl(urlstr + QLatin1String(".html"));
}
}
load(newurl);
}

QString WebView::lastStatusBarText() const
Expand Down

0 comments on commit 709ff2f

Please sign in to comment.