forked from blue/squawk
Better way to store expanded elements in roster, several clean ups, translations
This commit is contained in:
parent
7e9eed2075
commit
d162494ec8
18 changed files with 874 additions and 252 deletions
|
@ -30,16 +30,18 @@ Application::Application(Core::Squawk* p_core):
|
|||
storage(),
|
||||
trayIcon(nullptr),
|
||||
actionQuit(Shared::icon("application-exit"), tr("Quit")),
|
||||
actionToggle(tr("Minimize to tray"))
|
||||
actionToggle(QApplication::windowIcon(), tr("Minimize to tray")),
|
||||
expandedPaths()
|
||||
{
|
||||
connect(&actionQuit, &QAction::triggered, this, &Application::quit);
|
||||
connect(&actionToggle, &QAction::triggered, this, &Application::toggleSquawk);
|
||||
|
||||
connect(&roster, &Models::Roster::unnoticedMessage, this, &Application::notify);
|
||||
connect(&roster, &Models::Roster::unreadMessagesCountChanged, this, &Application::unreadMessagesCountChanged);
|
||||
connect(&roster, &Models::Roster::addedElement, this, &Application::onAddedElement);
|
||||
|
||||
|
||||
//connecting myself to the backed
|
||||
//connecting myself to the backend
|
||||
connect(this, &Application::changeState, core, &Core::Squawk::changeState);
|
||||
connect(this, &Application::setRoomJoined, core, &Core::Squawk::setRoomJoined);
|
||||
connect(this, &Application::setRoomAutoJoin, core, &Core::Squawk::setRoomAutoJoin);
|
||||
|
@ -70,7 +72,7 @@ Application::Application(Core::Squawk* p_core):
|
|||
connect(core, &Core::Squawk::changeAccount, this, &Application::changeAccount);
|
||||
connect(core, &Core::Squawk::removeAccount, this, &Application::removeAccount);
|
||||
|
||||
connect(core, &Core::Squawk::addContact, this, &Application::addContact);
|
||||
connect(core, &Core::Squawk::addContact, &roster, &Models::Roster::addContact);
|
||||
connect(core, &Core::Squawk::addGroup, this, &Application::addGroup);
|
||||
connect(core, &Core::Squawk::removeGroup, &roster, &Models::Roster::removeGroup);
|
||||
connect(core, qOverload<const QString&, const QString&>(&Core::Squawk::removeContact),
|
||||
|
@ -168,6 +170,8 @@ void Application::createMainWindow()
|
|||
connect(squawk, &Squawk::openConversation, this, &Application::openConversation);
|
||||
connect(squawk, &Squawk::changeState, this, &Application::setState);
|
||||
connect(squawk, &Squawk::changeTray, this, &Application::onChangeTray);
|
||||
connect(squawk, &Squawk::itemExpanded, this, &Application::onItemExpanded);
|
||||
connect(squawk, &Squawk::itemCollapsed, this, &Application::onItemCollapsed);
|
||||
connect(squawk, &Squawk::quit, this, &Application::quit);
|
||||
connect(squawk, &Squawk::closing, this, &Application::onSquawkClosing);
|
||||
|
||||
|
@ -192,7 +196,19 @@ void Application::createMainWindow()
|
|||
|
||||
dialogueQueue.setParentWidnow(squawk);
|
||||
squawk->stateChanged(availability);
|
||||
squawk->raise();
|
||||
squawk->show();
|
||||
squawk->activateWindow();
|
||||
|
||||
for (const std::list<QString>& entry : expandedPaths) {
|
||||
QModelIndex ind = roster.getIndexByPath(entry);
|
||||
if (ind.isValid()) {
|
||||
squawk->expand(ind);
|
||||
}
|
||||
}
|
||||
|
||||
connect(squawk, &Squawk::itemExpanded, this, &Application::onItemExpanded);
|
||||
connect(squawk, &Squawk::itemCollapsed, this, &Application::onItemCollapsed);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -292,6 +308,32 @@ void Application::toggleSquawk()
|
|||
}
|
||||
}
|
||||
|
||||
void Application::onItemCollapsed(const QModelIndex& index)
|
||||
{
|
||||
std::list<QString> address = roster.getItemPath(index);
|
||||
if (address.size() > 0) {
|
||||
expandedPaths.erase(address);
|
||||
}
|
||||
}
|
||||
|
||||
void Application::onItemExpanded(const QModelIndex& index)
|
||||
{
|
||||
std::list<QString> address = roster.getItemPath(index);
|
||||
if (address.size() > 0) {
|
||||
expandedPaths.insert(address);
|
||||
}
|
||||
}
|
||||
|
||||
void Application::onAddedElement(const std::list<QString>& path)
|
||||
{
|
||||
if (squawk != nullptr && expandedPaths.count(path) > 0) {
|
||||
QModelIndex index = roster.getIndexByPath(path);
|
||||
if (index.isValid()) {
|
||||
squawk->expand(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Application::notify(const QString& account, const Shared::Message& msg)
|
||||
{
|
||||
QString jid = msg.getPenPalJid();
|
||||
|
@ -427,6 +469,18 @@ void Application::readSettings()
|
|||
} else {
|
||||
avail = static_cast<int>(Shared::Availability::online);
|
||||
}
|
||||
|
||||
settings.beginGroup("roster");
|
||||
QStringList entries = settings.allKeys();
|
||||
for (const QString& entry : entries) {
|
||||
QStringList p = entry.split("/");
|
||||
if (p.last() == "expanded" && settings.value(entry, false).toBool()) {
|
||||
p.pop_back();
|
||||
expandedPaths.emplace(p.begin(), p.end());
|
||||
}
|
||||
}
|
||||
|
||||
settings.endGroup();
|
||||
settings.endGroup();
|
||||
|
||||
setState(Shared::Global::fromInt<Shared::Availability>(avail));
|
||||
|
@ -440,7 +494,22 @@ void Application::readSettings()
|
|||
void Application::writeSettings()
|
||||
{
|
||||
QSettings settings;
|
||||
settings.setValue("availability", static_cast<int>(availability));
|
||||
settings.beginGroup("ui");
|
||||
settings.setValue("availability", static_cast<int>(availability));
|
||||
|
||||
settings.remove("roster");
|
||||
settings.beginGroup("roster");
|
||||
for (const std::list<QString>& address : expandedPaths) {
|
||||
QString path = "";
|
||||
for (const QString& hop : address) {
|
||||
path += hop + "/";
|
||||
}
|
||||
path += "expanded";
|
||||
settings.setValue(path, true);
|
||||
}
|
||||
|
||||
settings.endGroup();
|
||||
settings.endGroup();
|
||||
}
|
||||
|
||||
void Application::requestPassword(const QString& account, bool authenticationError) {
|
||||
|
@ -611,25 +680,6 @@ void Application::changeAccount(const QString& account, const QMap<QString, QVar
|
|||
}
|
||||
}
|
||||
|
||||
void Application::addContact(const QString& account, const QString& jid, const QString& group, const QMap<QString, QVariant>& data)
|
||||
{
|
||||
roster.addContact(account, jid, group, data);
|
||||
|
||||
if (squawk != nullptr) {
|
||||
QSettings settings;
|
||||
settings.beginGroup("ui");
|
||||
settings.beginGroup("roster");
|
||||
settings.beginGroup(account);
|
||||
if (settings.value("expanded", false).toBool()) {
|
||||
QModelIndex ind = roster.getAccountIndex(account);
|
||||
squawk->expand(ind);
|
||||
}
|
||||
settings.endGroup();
|
||||
settings.endGroup();
|
||||
settings.endGroup();
|
||||
}
|
||||
}
|
||||
|
||||
void Application::addGroup(const QString& account, const QString& name)
|
||||
{
|
||||
roster.addGroup(account, name);
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
#define APPLICATION_H
|
||||
|
||||
#include <map>
|
||||
#include <list>
|
||||
#include <set>
|
||||
|
||||
#include <QObject>
|
||||
#include <QDBusInterface>
|
||||
|
@ -76,7 +78,6 @@ protected slots:
|
|||
void openConversation(const Models::Roster::ElId& id, const QString& resource = "");
|
||||
|
||||
void addGroup(const QString& account, const QString& name);
|
||||
void addContact(const QString& account, const QString& jid, const QString& group, const QMap<QString, QVariant>& data);
|
||||
|
||||
void requestPassword(const QString& account, bool authenticationError);
|
||||
|
||||
|
@ -97,6 +98,9 @@ private slots:
|
|||
void onChangeTray(bool enabled, bool hide);
|
||||
void trayClicked(QSystemTrayIcon::ActivationReason reason);
|
||||
void toggleSquawk();
|
||||
void onItemExpanded(const QModelIndex& index);
|
||||
void onItemCollapsed(const QModelIndex& index);
|
||||
void onAddedElement(const std::list<QString>& path);
|
||||
|
||||
private:
|
||||
void createMainWindow();
|
||||
|
@ -122,6 +126,7 @@ private:
|
|||
QSystemTrayIcon* trayIcon;
|
||||
QAction actionQuit;
|
||||
QAction actionToggle;
|
||||
std::set<std::list<QString>> expandedPaths;
|
||||
};
|
||||
|
||||
#endif // APPLICATION_H
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue