Commit 87848319 authored by Andreas Traczyk's avatar Andreas Traczyk

settingswidget: add/remove context menu access to settings

Change-Id: I0523dfe8ba00d8b5a0f1fbd06880df96ed63ed66
parent 739cffe7
......@@ -273,7 +273,7 @@ CallWidget::updateCustomUI()
}
void
CallWidget::slotAccountOnBoarded()
CallWidget::slotAccountListChanged()
{}
int
......
......@@ -63,7 +63,7 @@ public:
virtual void navigated(bool to);
virtual void updateCustomUI();
public slots:
virtual void slotAccountOnBoarded();
virtual void slotAccountListChanged();
public slots:
void on_ringContactLineEdit_returnPressed();
......
......@@ -110,13 +110,10 @@ public:
return getCurrentAccountInfo().callModel.get();
};
static const int getAccountNumList() {
return accountModel().getAccountList().size();
};
static const std::string& getCurrAccId() {
if (instance().selectedAccountId_.empty()) {
instance().selectedAccountId_ = accountModel().getAccountList().at(0);
auto accountList = accountModel().getAccountList();
if (instance().selectedAccountId_.empty() && accountList.size()) {
instance().selectedAccountId_ = accountList.at(0);
}
return instance().selectedAccountId_;
};
......@@ -183,8 +180,7 @@ public:
}
signals:
/// emit once at least one valid account is loaded
void accountOnBoarded();
void accountListChanged();
private:
std::unique_ptr<Lrc> lrc_;
......
......@@ -56,9 +56,9 @@ MainWindow::MainWindow(QWidget* parent)
navWidget->navigated(scr == i);
}
if (scr == ScreenEnum::WizardScreen) {
setWindowTitle(QStringLiteral("Log In"));
setWindowTitle(QObject::tr("Setup account"));
} else if (scr == ScreenEnum::SetttingsScreen) {
setWindowTitle(QStringLiteral("Settings"));
setWindowTitle(QObject::tr("Settings"));
} else {
setWindowTitle(QStringLiteral("Jami"));
}
......@@ -75,34 +75,73 @@ MainWindow::MainWindow(QWidget* parent)
QIcon icon(":images/jami.png");
this->setWindowIcon(icon);
setContextMenuPolicy(Qt::NoContextMenu);
connect(&GlobalSystemTray::instance(), SIGNAL(messageClicked()), this, SLOT(notificationClicked()));
connect(&netManager_, &QNetworkConfigurationManager::onlineStateChanged,
[=](bool online) {
Q_UNUSED(online);
LRCInstance::connectivityChanged();
});
auto flags_ = windowFlags();
auto accountList = LRCInstance::accountModel().getAccountList();
lastAccountCount_ = accountList.size();
ScreenEnum startScreen;
if (accountList.size()) {
readSettingsFromRegistry();
startScreen = ScreenEnum::CallScreen;
emit LRCInstance::instance().accountListChanged();
setWindowTitle(QStringLiteral("Jami"));
} else {
startScreen = ScreenEnum::WizardScreen;
setWindowTitle(QStringLiteral("Log In"));
}
Utils::setStackWidget(ui->navStack, ui->navStack->widget(startScreen));
if (startScreen == ScreenEnum::WizardScreen) {
setWindowSize(startScreen);
}
if (auto navWidget = dynamic_cast<NavWidget*>(ui->navStack->widget(startScreen))) {
navWidget->navigated(true);
}
lastScr_ = startScreen;
// systray menu
GlobalSystemTray& sysIcon = GlobalSystemTray::instance();
sysIcon.setIcon(icon);
QMenu* menu = new QMenu();
auto configAction = new QAction(tr("Settings"), this);
connect(configAction, &QAction::triggered,
settingsAction_ = new QAction(tr("Settings"), this);
connect(settingsAction_, &QAction::triggered,
[this]() {
if (auto currentWidget = dynamic_cast<NavWidget*>(ui->navStack->currentWidget())) {
emit currentWidget->NavigationRequested(ScreenEnum::SetttingsScreen);
showWindow();
}
});
menu->addAction(configAction);
auto exitAction = new QAction(tr("Exit"), this);
connect(exitAction, &QAction::triggered,
[this]() {
QCoreApplication::exit();
});
menu->addAction(exitAction);
exitAction_ = new QAction(tr("Exit"), this);
connect(exitAction_, &QAction::triggered,
[this]() { QCoreApplication::exit(); });
sysIcon.setContextMenu(menu);
sysIcon.show();
connect(&sysIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
this, SLOT(trayActivated(QSystemTrayIcon::ActivationReason)));
this, SLOT(trayActivated(QSystemTrayIcon::ActivationReason)));
slotAccountListChanged();
// only add settings action once in the principal interface
connect(&LRCInstance::instance(), &LRCInstance::accountListChanged,
this, &MainWindow::slotAccountListChanged);
// about menu
#ifdef Q_OS_WIN
HMENU sysMenu = ::GetSystemMenu((HWND)winId(), FALSE);
if (sysMenu != NULL) {
......@@ -122,50 +161,15 @@ MainWindow::MainWindow(QWidget* parent)
updateTimer_ = new QTimer(this);
connect(updateTimer_, &QTimer::timeout,
[this]() {
QSettings settings("jami.net", "Jami");
if (settings.value(SettingsKey::autoUpdate).toBool()) {
Utils::checkForUpdates(false, this);
}
});
QSettings settings("jami.net", "Jami");
if (settings.value(SettingsKey::autoUpdate).toBool()) {
Utils::checkForUpdates(false, this);
}
});
long updateCheckDelay = 4 * 86400 * 1000;
updateTimer_->start(updateCheckDelay);
#endif
setContextMenuPolicy(Qt::NoContextMenu);
connect(&GlobalSystemTray::instance(), SIGNAL(messageClicked()), this, SLOT(notificationClicked()));
connect(&netManager_, &QNetworkConfigurationManager::onlineStateChanged,
[=](bool online) {
Q_UNUSED(online);
LRCInstance::connectivityChanged();
});
auto flags_ = windowFlags();
auto accountList = LRCInstance::accountModel().getAccountList();
lastAccountCount_ = accountList.size();
ScreenEnum startScreen;
if (accountList.size()) {
readSettingsFromRegistry();
startScreen = ScreenEnum::CallScreen;
emit LRCInstance::instance().accountOnBoarded();
setWindowTitle(QStringLiteral("Jami"));
} else {
startScreen = ScreenEnum::WizardScreen;
setWindowTitle(QStringLiteral("Log In"));
}
Utils::setStackWidget(ui->navStack, ui->navStack->widget(startScreen));
if (startScreen == ScreenEnum::WizardScreen) {
setWindowSize(startScreen);
}
if (auto navWidget = dynamic_cast<NavWidget*>(ui->navStack->widget(startScreen))) {
navWidget->navigated(true);
}
lastScr_ = startScreen;
#ifdef DEBUG_STYLESHEET
QTimer *timer = new QTimer(this);
connect(timer, &QTimer::timeout,
......@@ -389,3 +393,15 @@ void MainWindow::keyReleaseEvent(QKeyEvent* ke)
emit keyReleased(ke);
QMainWindow::keyReleaseEvent(ke);
}
void MainWindow::slotAccountListChanged()
{
auto systrayMenu = GlobalSystemTray::instance().contextMenu();
systrayMenu->clear();
if (LRCInstance::accountModel().getAccountList().size()) {
systrayMenu->addAction(settingsAction_);
systrayMenu->addAction(exitAction_);
} else {
systrayMenu->addAction(exitAction_);
}
}
......@@ -69,6 +69,7 @@ private slots:
void trayActivated(QSystemTrayIcon::ActivationReason reason);
void notificationClicked();
void slotScreenChanged(QScreen* screen);
void slotAccountListChanged();
private:
explicit MainWindow(QWidget* parent = 0);
......@@ -83,6 +84,9 @@ private:
void readSettingsFromRegistry();
QAction* settingsAction_;
QAction* exitAction_;
Ui::MainWindow* ui;
QNetworkConfigurationManager netManager_;
QMetaObject::Connection screenChangedConnection_;
......
......@@ -24,8 +24,8 @@
NavWidget::NavWidget(QWidget* parent) :
QWidget(parent)
{
Utils::oneShotConnect(&LRCInstance::instance(), &LRCInstance::accountOnBoarded,
this, &NavWidget::slotAccountOnBoarded);
Utils::oneShotConnect(&LRCInstance::instance(), &LRCInstance::accountListChanged,
this, &NavWidget::slotAccountListChanged);
}
NavWidget::~NavWidget()
......
......@@ -43,6 +43,6 @@ signals:
void NavigationRequested(ScreenEnum screen);
protected slots:
virtual void slotAccountOnBoarded() = 0;
virtual void slotAccountListChanged() = 0;
};
......@@ -157,7 +157,7 @@ NewWizardWidget::navigated(bool to)
}
void
NewWizardWidget::slotAccountOnBoarded()
NewWizardWidget::slotAccountListChanged()
{}
void
......@@ -465,7 +465,7 @@ NewWizardWidget::createAccount()
lrc::api::account::ConfProperties_t accountProperties = LRCInstance::accountModel().getAccountConfig(LRCInstance::getCurrAccId());
LRCInstance::accountModel().setAccountConfig(LRCInstance::getCurrAccId(), accountProperties);
emit NavigationRequested(ScreenEnum::CallScreen);
emit LRCInstance::instance().accountOnBoarded();
emit LRCInstance::instance().accountListChanged();
});
LRCInstance::accountModel().registerName(
LRCInstance::getCurrAccId(),
......@@ -474,7 +474,7 @@ NewWizardWidget::createAccount()
);
} else {
emit NavigationRequested(ScreenEnum::CallScreen);
emit LRCInstance::instance().accountOnBoarded();
emit LRCInstance::instance().accountListChanged();
}
LRCInstance::setCurrAccAvatar(ui->setAvatarWidget->getAvatarPixmap());
} else {
......@@ -515,7 +515,7 @@ NewWizardWidget::createAccount()
);
QThread::sleep(2);
emit NavigationRequested(ScreenEnum::CallScreen);
emit LRCInstance::instance().accountOnBoarded();
emit LRCInstance::instance().accountListChanged();
}
});
changePage(ui->spinnerPage);
......
......@@ -56,7 +56,7 @@ public:
virtual void navigated(bool to);
virtual void updateCustomUI();
public slots:
virtual void slotAccountOnBoarded();
virtual void slotAccountListChanged();
//UI Slots
private slots:
......
This diff is collapsed.
......@@ -49,7 +49,7 @@ public:
virtual void navigated(bool to);
virtual void updateCustomUI();
public slots:
virtual void slotAccountOnBoarded();
virtual void slotAccountListChanged();
private:
Ui::SettingsWidget* ui;
......@@ -78,7 +78,8 @@ private:
void setRegNameUi(RegName stat);
void removeDeviceSlot(int index);
void unban(int index);
void setConnections();
void connectCurrentAccount();
void disconnectAccountConnections();
void populateGeneralSettings();
void populateAVSettings();
void setFormatListForDevice(const std::string& device);
......@@ -89,6 +90,7 @@ private:
void startAudioMeter(bool blocking = false);
void stopAudioMeter(bool blocking = false);
QList<QMetaObject::Connection> accountConnections_;
QString registeredName_;
lrc::api::account::ConfProperties_t confProps_;
AdvancedSettingsWidget* advancedSettingsWidget_;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment