mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 19:08:58 +03:00
Merge pull request #306 from LorenDB/master
Add option for separate profiles
This commit is contained in:
commit
592bf42640
7 changed files with 69 additions and 24 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
@ -751,18 +751,6 @@ ChatPage::bootstrap(QString userid, QString homeserver, QString token)
|
|||
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
|
||||
ChatPage::loadStateFromCache()
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
@ -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
|
||||
MainWindow::showEvent(QShowEvent *event)
|
||||
{
|
||||
|
|
|
@ -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_;
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
|
|
42
src/main.cpp
42
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()));
|
||||
|
|
Loading…
Reference in a new issue