diff --git a/README.md b/README.md
index 92b55460..ee42cb0c 100644
--- a/README.md
+++ b/README.md
@@ -41,6 +41,7 @@ Specifically there is support for:
- Basic communities support.
- Room switcher (ctrl-K).
- Light, Dark & System themes.
+- Creating separate profiles (command line only, use `--profile=name`).
## Installation
diff --git a/src/ChatPage.cpp b/src/ChatPage.cpp
index 103905d1..235c5ea7 100644
--- a/src/ChatPage.cpp
+++ b/src/ChatPage.cpp
@@ -272,7 +272,7 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent)
connect(room_list_,
SIGNAL(totalUnreadMessageCountUpdated(int)),
this,
- SLOT(showUnreadMessageNotification(int)));
+ SIGNAL(unreadMessages(int)));
connect(text_input_,
&TextInputWidget::sendTextMessage,
@@ -626,7 +626,7 @@ ChatPage::resetUI()
user_info_widget_->reset();
view_manager_->clearAll();
- showUnreadMessageNotification(0);
+ emit unreadMessages(0);
}
void
@@ -752,18 +752,6 @@ ChatPage::bootstrap(QString userid, QString homeserver, QString token)
}
void
-ChatPage::showUnreadMessageNotification(int count)
-{
- emit unreadMessages(count);
-
- // TODO: Make the default title a const.
- if (count == 0)
- emit changeWindowTitle("nheko");
- else
- emit changeWindowTitle(QString("nheko (%1)").arg(count));
-}
-
-void
ChatPage::loadStateFromCache()
{
emit contentLoaded();
diff --git a/src/ChatPage.h b/src/ChatPage.h
index bf649cc9..a29cea7b 100644
--- a/src/ChatPage.h
+++ b/src/ChatPage.h
@@ -130,7 +130,7 @@ signals:
void contentLoaded();
void closing();
- void changeWindowTitle(const QString &msg);
+ void changeWindowTitle(const int);
void unreadMessages(int count);
void showNotification(const QString &msg);
void showLoginPage(const QString &msg);
@@ -188,7 +188,6 @@ signals:
void receivedDeviceVerificationDone(const mtx::events::msg::KeyVerificationDone &message);
private slots:
- void showUnreadMessageNotification(int count);
void logout();
void removeRoom(const QString &room_id);
void dropToLoginPage(const QString &msg);
diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp
index b6ad8bbe..c019b24b 100644
--- a/src/MainWindow.cpp
+++ b/src/MainWindow.cpp
@@ -53,10 +53,11 @@
MainWindow *MainWindow::instance_ = nullptr;
-MainWindow::MainWindow(QWidget *parent)
- : QMainWindow(parent)
+MainWindow::MainWindow(const QString profile, QWidget *parent)
+ : QMainWindow(parent),
+ profile_{ profile }
{
- setWindowTitle("nheko");
+ setWindowTitle(0);
setObjectName("MainWindow");
modal_ = new OverlayModal(this);
@@ -104,7 +105,7 @@ MainWindow::MainWindow(QWidget *parent)
connect(
chat_page_, &ChatPage::showOverlayProgressBar, this, &MainWindow::showOverlayProgressBar);
connect(
- chat_page_, SIGNAL(changeWindowTitle(QString)), this, SLOT(setWindowTitle(QString)));
+ chat_page_, &ChatPage::unreadMessages, this, &MainWindow::setWindowTitle);
connect(chat_page_, SIGNAL(unreadMessages(int)), trayIcon_, SLOT(setUnreadCount(int)));
connect(chat_page_, &ChatPage::showLoginPage, this, [this](const QString &msg) {
login_page_->loginError(msg);
@@ -179,6 +180,19 @@ MainWindow::MainWindow(QWidget *parent)
}
void
+MainWindow::setWindowTitle(int notificationCount)
+{
+ QString name = "nheko";
+ if (!profile_.isEmpty())
+ name += " | " + profile_;
+ if (notificationCount > 0)
+ {
+ name.append(QString{" (%1)"}.arg(notificationCount));
+ }
+ QMainWindow::setWindowTitle(name);
+}
+
+void
MainWindow::showEvent(QShowEvent *event)
{
adjustSideBars();
diff --git a/src/MainWindow.h b/src/MainWindow.h
index e66f299f..2f9ff897 100644
--- a/src/MainWindow.h
+++ b/src/MainWindow.h
@@ -62,7 +62,7 @@ class MainWindow : public QMainWindow
Q_OBJECT
public:
- explicit MainWindow(QWidget *parent = nullptr);
+ explicit MainWindow(const QString name, QWidget *parent = nullptr);
static MainWindow *instance() { return instance_; };
void saveCurrentWindowSize();
@@ -113,6 +113,8 @@ private slots:
void showOverlayProgressBar();
void removeOverlayProgressBar();
+ virtual void setWindowTitle(int notificationCount);
+
private:
bool loadJdenticonPlugin();
@@ -147,4 +149,6 @@ private:
LoadingIndicator *spinner_ = nullptr;
JdenticonInterface *jdenticonInteface_ = nullptr;
+
+ QString profile_;
};
diff --git a/src/UserSettingsPage.cpp b/src/UserSettingsPage.cpp
index 6fd31de3..53539407 100644
--- a/src/UserSettingsPage.cpp
+++ b/src/UserSettingsPage.cpp
@@ -36,6 +36,7 @@
#include <QString>
#include <QTextStream>
#include <QtQml>
+#include <QCoreApplication>
#include "Cache.h"
#include "Config.h"
@@ -446,6 +447,8 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
font.setPointSizeF(font.pointSizeF() * 1.1);
auto versionInfo = new QLabel(QString("%1 | %2").arg(nheko::version).arg(nheko::build_os));
+ if (QCoreApplication::applicationName() != "nheko")
+ versionInfo->setText(versionInfo->text() + " | " + tr("profile: %1").arg(QCoreApplication::applicationName()));
versionInfo->setTextInteractionFlags(Qt::TextBrowserInteraction);
topBarLayout_ = new QHBoxLayout;
diff --git a/src/main.cpp b/src/main.cpp
index e02ffa36..61cb4fbe 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -104,10 +104,37 @@ createCacheDirectory()
int
main(int argc, char *argv[])
{
- // needed for settings so need to register before any settings are read to prevent warings
+ // needed for settings so need to register before any settings are read to prevent warnings
qRegisterMetaType<UserSettings::Presence>();
- QCoreApplication::setApplicationName("nheko");
+ // This is some hacky programming, but it's necessary (AFAIK?) to get the unique config name parsed
+ // before the app name is set.
+ QString appName{"nheko"};
+ for (int i = 0; i < argc; ++i)
+ {
+ if (QString{argv[i]}.startsWith("--profile="))
+ {
+ QString q{argv[i]};
+ q.remove("--profile=");
+ appName += "-" + q;
+ }
+ else if (QString{argv[i]}.startsWith("--p="))
+ {
+ QString q{argv[i]};
+ q.remove("-p=");
+ appName += "-" + q;
+ }
+ else if (QString{argv[i]} == "--profile" || QString{argv[i]} == "-p")
+ {
+ if (i < argc -1) // if i is less than argc - 1, we still have a parameter left to process as the name
+ {
+ ++i; // the next arg is the name, so increment
+ appName += "-" + QString {argv[i]};
+ }
+ }
+ }
+
+ QCoreApplication::setApplicationName(appName);
QCoreApplication::setApplicationVersion(nheko::version);
QCoreApplication::setOrganizationName("nheko");
QCoreApplication::setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);
@@ -137,6 +164,15 @@ main(int argc, char *argv[])
parser.addVersionOption();
QCommandLineOption debugOption("debug", "Enable debug output");
parser.addOption(debugOption);
+
+ // This option is not actually parsed via Qt due to the need to parse it before the app
+ // name is set. It only exists to keep Qt from complaining about the --profile/-p
+ // option and thereby crashing the app.
+ QCommandLineOption configName(QStringList() << "p" << "profile",
+ QCoreApplication::tr("Create a unique profile, which allows you to log into several accounts at the same time and start multiple instances of nheko."),
+ QCoreApplication::tr("profile"), QCoreApplication::tr("profile name"));
+ parser.addOption(configName);
+
parser.process(app);
app.setWindowIcon(QIcon(":/logos/nheko.png"));
@@ -181,7 +217,7 @@ main(int argc, char *argv[])
appTranslator.load(QLocale(), "nheko", "_", ":/translations");
app.installTranslator(&appTranslator);
- MainWindow w;
+ MainWindow w{ (appName == "nheko" ? "" : appName.remove("nheko-")) };
// Move the MainWindow to the center
w.move(screenCenter(w.width(), w.height()));
|