Merge pull request #306 from LorenDB/master

Add option for separate profiles
This commit is contained in:
DeepBlueV7.X 2020-10-24 18:08:42 +02:00 committed by GitHub
commit 592bf42640
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 69 additions and 24 deletions

View file

@ -41,6 +41,7 @@ Specifically there is support for:
- Basic communities support. - Basic communities support.
- Room switcher (ctrl-K). - Room switcher (ctrl-K).
- Light, Dark & System themes. - Light, Dark & System themes.
- Creating separate profiles (command line only, use `--profile=name`).
## Installation ## Installation

View file

@ -272,7 +272,7 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent)
connect(room_list_, connect(room_list_,
SIGNAL(totalUnreadMessageCountUpdated(int)), SIGNAL(totalUnreadMessageCountUpdated(int)),
this, this,
SLOT(showUnreadMessageNotification(int))); SIGNAL(unreadMessages(int)));
connect(text_input_, connect(text_input_,
&TextInputWidget::sendTextMessage, &TextInputWidget::sendTextMessage,
@ -626,7 +626,7 @@ ChatPage::resetUI()
user_info_widget_->reset(); user_info_widget_->reset();
view_manager_->clearAll(); view_manager_->clearAll();
showUnreadMessageNotification(0); emit unreadMessages(0);
} }
void void
@ -751,18 +751,6 @@ ChatPage::bootstrap(QString userid, QString homeserver, QString token)
tryInitialSync(); tryInitialSync();
} }
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 void
ChatPage::loadStateFromCache() ChatPage::loadStateFromCache()
{ {

View file

@ -130,7 +130,7 @@ signals:
void contentLoaded(); void contentLoaded();
void closing(); void closing();
void changeWindowTitle(const QString &msg); void changeWindowTitle(const int);
void unreadMessages(int count); void unreadMessages(int count);
void showNotification(const QString &msg); void showNotification(const QString &msg);
void showLoginPage(const QString &msg); void showLoginPage(const QString &msg);
@ -188,7 +188,6 @@ signals:
void receivedDeviceVerificationDone(const mtx::events::msg::KeyVerificationDone &message); void receivedDeviceVerificationDone(const mtx::events::msg::KeyVerificationDone &message);
private slots: private slots:
void showUnreadMessageNotification(int count);
void logout(); void logout();
void removeRoom(const QString &room_id); void removeRoom(const QString &room_id);
void dropToLoginPage(const QString &msg); void dropToLoginPage(const QString &msg);

View file

@ -53,10 +53,11 @@
MainWindow *MainWindow::instance_ = nullptr; MainWindow *MainWindow::instance_ = nullptr;
MainWindow::MainWindow(QWidget *parent) MainWindow::MainWindow(const QString profile, QWidget *parent)
: QMainWindow(parent) : QMainWindow(parent),
profile_{ profile }
{ {
setWindowTitle("nheko"); setWindowTitle(0);
setObjectName("MainWindow"); setObjectName("MainWindow");
modal_ = new OverlayModal(this); modal_ = new OverlayModal(this);
@ -104,7 +105,7 @@ MainWindow::MainWindow(QWidget *parent)
connect( connect(
chat_page_, &ChatPage::showOverlayProgressBar, this, &MainWindow::showOverlayProgressBar); chat_page_, &ChatPage::showOverlayProgressBar, this, &MainWindow::showOverlayProgressBar);
connect( 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_, SIGNAL(unreadMessages(int)), trayIcon_, SLOT(setUnreadCount(int)));
connect(chat_page_, &ChatPage::showLoginPage, this, [this](const QString &msg) { connect(chat_page_, &ChatPage::showLoginPage, this, [this](const QString &msg) {
login_page_->loginError(msg); login_page_->loginError(msg);
@ -178,6 +179,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 void
MainWindow::showEvent(QShowEvent *event) MainWindow::showEvent(QShowEvent *event)
{ {

View file

@ -62,7 +62,7 @@ class MainWindow : public QMainWindow
Q_OBJECT Q_OBJECT
public: public:
explicit MainWindow(QWidget *parent = nullptr); explicit MainWindow(const QString name, QWidget *parent = nullptr);
static MainWindow *instance() { return instance_; }; static MainWindow *instance() { return instance_; };
void saveCurrentWindowSize(); void saveCurrentWindowSize();
@ -113,6 +113,8 @@ private slots:
void showOverlayProgressBar(); void showOverlayProgressBar();
void removeOverlayProgressBar(); void removeOverlayProgressBar();
virtual void setWindowTitle(int notificationCount);
private: private:
bool loadJdenticonPlugin(); bool loadJdenticonPlugin();
@ -147,4 +149,6 @@ private:
LoadingIndicator *spinner_ = nullptr; LoadingIndicator *spinner_ = nullptr;
JdenticonInterface *jdenticonInteface_ = nullptr; JdenticonInterface *jdenticonInteface_ = nullptr;
QString profile_;
}; };

View file

@ -36,6 +36,7 @@
#include <QString> #include <QString>
#include <QTextStream> #include <QTextStream>
#include <QtQml> #include <QtQml>
#include <QCoreApplication>
#include "Cache.h" #include "Cache.h"
#include "Config.h" #include "Config.h"
@ -446,6 +447,8 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
font.setPointSizeF(font.pointSizeF() * 1.1); font.setPointSizeF(font.pointSizeF() * 1.1);
auto versionInfo = new QLabel(QString("%1 | %2").arg(nheko::version).arg(nheko::build_os)); 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); versionInfo->setTextInteractionFlags(Qt::TextBrowserInteraction);
topBarLayout_ = new QHBoxLayout; topBarLayout_ = new QHBoxLayout;

View file

@ -104,10 +104,37 @@ createCacheDirectory()
int int
main(int argc, char *argv[]) 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>(); 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::setApplicationVersion(nheko::version);
QCoreApplication::setOrganizationName("nheko"); QCoreApplication::setOrganizationName("nheko");
QCoreApplication::setAttribute(Qt::AA_DontCreateNativeWidgetSiblings); QCoreApplication::setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);
@ -137,6 +164,15 @@ main(int argc, char *argv[])
parser.addVersionOption(); parser.addVersionOption();
QCommandLineOption debugOption("debug", "Enable debug output"); QCommandLineOption debugOption("debug", "Enable debug output");
parser.addOption(debugOption); 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); parser.process(app);
app.setWindowIcon(QIcon(":/logos/nheko.png")); app.setWindowIcon(QIcon(":/logos/nheko.png"));
@ -181,7 +217,7 @@ main(int argc, char *argv[])
appTranslator.load(QLocale(), "nheko", "_", ":/translations"); appTranslator.load(QLocale(), "nheko", "_", ":/translations");
app.installTranslator(&appTranslator); app.installTranslator(&appTranslator);
MainWindow w; MainWindow w{ (appName == "nheko" ? "" : appName.remove("nheko-")) };
// Move the MainWindow to the center // Move the MainWindow to the center
w.move(screenCenter(w.width(), w.height())); w.move(screenCenter(w.width(), w.height()));