forked from blue/squawk
cleanup some warnings suppression
This commit is contained in:
parent
5fbb03fc46
commit
23ec80ccba
26 changed files with 630 additions and 924 deletions
|
@ -120,8 +120,7 @@ Application::Application(Core::Squawk* p_core):
|
|||
|
||||
Application::~Application() {}
|
||||
|
||||
void Application::quit()
|
||||
{
|
||||
void Application::quit() {
|
||||
if (!nowQuitting) {
|
||||
nowQuitting = true;
|
||||
emit quitting();
|
||||
|
@ -135,32 +134,27 @@ void Application::quit()
|
|||
conversations.clear();
|
||||
dialogueQueue.quit();
|
||||
|
||||
if (squawk != nullptr) {
|
||||
if (squawk != nullptr)
|
||||
squawk->close();
|
||||
}
|
||||
|
||||
if (trayIcon != nullptr) {
|
||||
trayIcon->deleteLater();
|
||||
trayIcon = nullptr;
|
||||
}
|
||||
|
||||
if (!destroyingSquawk) {
|
||||
if (!destroyingSquawk)
|
||||
checkForTheLastWindow();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Application::checkForTheLastWindow()
|
||||
{
|
||||
if (QApplication::topLevelWidgets().size() > 0) {
|
||||
void Application::checkForTheLastWindow() {
|
||||
if (QApplication::topLevelWidgets().size() > 0)
|
||||
emit readyToQuit();
|
||||
} else {
|
||||
else
|
||||
connect(qApp, &QApplication::lastWindowClosed, this, &Application::readyToQuit);
|
||||
}
|
||||
}
|
||||
|
||||
void Application::createMainWindow()
|
||||
{
|
||||
void Application::createMainWindow() {
|
||||
if (squawk == nullptr) {
|
||||
squawk = new Squawk(roster);
|
||||
|
||||
|
@ -202,9 +196,8 @@ void Application::createMainWindow()
|
|||
|
||||
for (const std::list<QString>& entry : expandedPaths) {
|
||||
QModelIndex ind = roster.getIndexByPath(entry);
|
||||
if (ind.isValid()) {
|
||||
if (ind.isValid())
|
||||
squawk->expand(ind);
|
||||
}
|
||||
}
|
||||
|
||||
connect(squawk, &Squawk::itemExpanded, this, &Application::onItemExpanded);
|
||||
|
@ -212,8 +205,7 @@ void Application::createMainWindow()
|
|||
}
|
||||
}
|
||||
|
||||
void Application::onSquawkClosing()
|
||||
{
|
||||
void Application::onSquawkClosing() {
|
||||
dialogueQueue.setParentWidnow(nullptr);
|
||||
|
||||
if (!nowQuitting) {
|
||||
|
@ -237,18 +229,15 @@ void Application::onSquawkClosing()
|
|||
|
||||
void Application::onSquawkDestroyed() {
|
||||
destroyingSquawk = false;
|
||||
if (nowQuitting) {
|
||||
if (nowQuitting)
|
||||
checkForTheLastWindow();
|
||||
}
|
||||
}
|
||||
|
||||
void Application::onChangeTray(bool enabled, bool hide)
|
||||
{
|
||||
void Application::onChangeTray(bool enabled, bool hide) {
|
||||
if (enabled) {
|
||||
if (trayIcon == nullptr) {
|
||||
if (!hide || squawk == nullptr) {
|
||||
if (!hide || squawk == nullptr)
|
||||
createTrayIcon();
|
||||
}
|
||||
} else {
|
||||
if (hide && squawk != nullptr) {
|
||||
trayIcon->deleteLater();
|
||||
|
@ -261,8 +250,7 @@ void Application::onChangeTray(bool enabled, bool hide)
|
|||
}
|
||||
}
|
||||
|
||||
void Application::createTrayIcon()
|
||||
{
|
||||
void Application::createTrayIcon() {
|
||||
trayIcon = new QSystemTrayIcon();
|
||||
|
||||
QMenu* trayIconMenu = new QMenu();
|
||||
|
@ -279,8 +267,7 @@ void Application::createTrayIcon()
|
|||
trayIcon->show();
|
||||
}
|
||||
|
||||
void Application::trayClicked(QSystemTrayIcon::ActivationReason reason)
|
||||
{
|
||||
void Application::trayClicked(QSystemTrayIcon::ActivationReason reason) {
|
||||
switch (reason) {
|
||||
case QSystemTrayIcon::Trigger:
|
||||
case QSystemTrayIcon::DoubleClick:
|
||||
|
@ -292,8 +279,7 @@ void Application::trayClicked(QSystemTrayIcon::ActivationReason reason)
|
|||
}
|
||||
}
|
||||
|
||||
void Application::toggleSquawk()
|
||||
{
|
||||
void Application::toggleSquawk() {
|
||||
QSettings settings;
|
||||
if (squawk == nullptr) {
|
||||
createMainWindow();
|
||||
|
@ -308,34 +294,27 @@ void Application::toggleSquawk()
|
|||
}
|
||||
}
|
||||
|
||||
void Application::onItemCollapsed(const QModelIndex& index)
|
||||
{
|
||||
void Application::onItemCollapsed(const QModelIndex& index) {
|
||||
std::list<QString> address = roster.getItemPath(index);
|
||||
if (address.size() > 0) {
|
||||
if (address.size() > 0)
|
||||
expandedPaths.erase(address);
|
||||
}
|
||||
}
|
||||
|
||||
void Application::onItemExpanded(const QModelIndex& index)
|
||||
{
|
||||
void Application::onItemExpanded(const QModelIndex& index) {
|
||||
std::list<QString> address = roster.getItemPath(index);
|
||||
if (address.size() > 0) {
|
||||
if (address.size() > 0)
|
||||
expandedPaths.insert(address);
|
||||
}
|
||||
}
|
||||
|
||||
void Application::onAddedElement(const std::list<QString>& path)
|
||||
{
|
||||
void Application::onAddedElement(const std::list<QString>& path) {
|
||||
if (squawk != nullptr && expandedPaths.count(path) > 0) {
|
||||
QModelIndex index = roster.getIndexByPath(path);
|
||||
if (index.isValid()) {
|
||||
if (index.isValid())
|
||||
squawk->expand(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Application::notify(const QString& account, const Shared::Message& msg)
|
||||
{
|
||||
void Application::notify(const QString& account, const Shared::Message& msg) {
|
||||
QString jid = msg.getPenPalJid();
|
||||
QString name = QString(roster.getContactName(account, jid));
|
||||
QString path = QString(roster.getContactIconPath(account, jid, msg.getPenPalResource()));
|
||||
|
@ -344,16 +323,15 @@ void Application::notify(const QString& account, const Shared::Message& msg)
|
|||
|
||||
uint32_t notificationId = qHash(msg.getId());
|
||||
args << notificationId;
|
||||
if (path.size() > 0) {
|
||||
if (path.size() > 0)
|
||||
args << path;
|
||||
} else {
|
||||
else
|
||||
args << QString("mail-message"); //TODO should here better be unknown user icon?
|
||||
}
|
||||
if (msg.getType() == Shared::Message::groupChat) {
|
||||
|
||||
if (msg.getType() == Shared::Message::groupChat)
|
||||
args << msg.getFromResource() + tr(" from ") + name;
|
||||
} else {
|
||||
else
|
||||
args << name;
|
||||
}
|
||||
|
||||
QString body(msg.getBody());
|
||||
QString oob(msg.getOutOfBandUrl());
|
||||
|
@ -378,13 +356,11 @@ void Application::notify(const QString& account, const Shared::Message& msg)
|
|||
|
||||
storage.insert(std::make_pair(notificationId, std::make_pair(Models::Roster::ElId(account, name), msg.getId())));
|
||||
|
||||
if (squawk != nullptr) {
|
||||
if (squawk != nullptr)
|
||||
QApplication::alert(squawk);
|
||||
}
|
||||
}
|
||||
|
||||
void Application::onNotificationClosed(quint32 id, quint32 reason)
|
||||
{
|
||||
void Application::onNotificationClosed(quint32 id, quint32 reason) {
|
||||
Notifications::const_iterator itr = storage.find(id);
|
||||
if (itr != storage.end()) {
|
||||
if (reason == 2) { //dissmissed by user (https://specifications.freedesktop.org/notification-spec/latest/ar01s09.html)
|
||||
|
@ -397,21 +373,18 @@ void Application::onNotificationClosed(quint32 id, quint32 reason)
|
|||
}
|
||||
}
|
||||
|
||||
void Application::onNotificationInvoked(quint32 id, const QString& action)
|
||||
{
|
||||
void Application::onNotificationInvoked(quint32 id, const QString& action) {
|
||||
qDebug() << "Notification" << id << action << "request";
|
||||
Notifications::const_iterator itr = storage.find(id);
|
||||
if (itr != storage.end()) {
|
||||
if (action == "markAsRead") {
|
||||
if (action == "markAsRead")
|
||||
roster.markMessageAsRead(itr->second.first, itr->second.second);
|
||||
} else if (action == "openConversation") {
|
||||
else if (action == "openConversation")
|
||||
focusConversation(itr->second.first, "", itr->second.second);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Application::unreadMessagesCountChanged(int count)
|
||||
{
|
||||
void Application::unreadMessagesCountChanged(int count) {
|
||||
QDBusMessage signal = QDBusMessage::createSignal("/", "com.canonical.Unity.LauncherEntry", "Update");
|
||||
signal << qApp->desktopFileName() + QLatin1String(".desktop");
|
||||
signal << QVariantMap ({
|
||||
|
@ -421,54 +394,49 @@ void Application::unreadMessagesCountChanged(int count)
|
|||
QDBusConnection::sessionBus().send(signal);
|
||||
}
|
||||
|
||||
void Application::focusConversation(const Models::Roster::ElId& id, const QString& resource, const QString& messageId)
|
||||
{
|
||||
void Application::focusConversation(const Models::Roster::ElId& id, const QString& resource, const QString& messageId) {
|
||||
if (squawk != nullptr) {
|
||||
if (squawk->currentConversationId() != id) {
|
||||
QModelIndex index = roster.getContactIndex(id.account, id.name, resource);
|
||||
squawk->select(index);
|
||||
}
|
||||
|
||||
if (squawk->isMinimized()) {
|
||||
if (squawk->isMinimized())
|
||||
squawk->showNormal();
|
||||
} else {
|
||||
else
|
||||
squawk->show();
|
||||
}
|
||||
|
||||
squawk->raise();
|
||||
squawk->activateWindow();
|
||||
} else {
|
||||
openConversation(id, resource);
|
||||
}
|
||||
|
||||
SHARED_UNUSED(messageId);
|
||||
//TODO focus messageId;
|
||||
}
|
||||
|
||||
void Application::setState(Shared::Availability p_availability)
|
||||
{
|
||||
void Application::setState(Shared::Availability p_availability) {
|
||||
if (availability != p_availability) {
|
||||
availability = p_availability;
|
||||
emit changeState(availability);
|
||||
}
|
||||
}
|
||||
|
||||
void Application::stateChanged(Shared::Availability state)
|
||||
{
|
||||
void Application::stateChanged(Shared::Availability state) {
|
||||
availability = state;
|
||||
if (squawk != nullptr) {
|
||||
if (squawk != nullptr)
|
||||
squawk->stateChanged(state);
|
||||
}
|
||||
}
|
||||
|
||||
void Application::readSettings()
|
||||
{
|
||||
void Application::readSettings() {
|
||||
QSettings settings;
|
||||
settings.beginGroup("ui");
|
||||
int avail;
|
||||
if (settings.contains("availability")) {
|
||||
if (settings.contains("availability"))
|
||||
avail = settings.value("availability").toInt();
|
||||
} else {
|
||||
else
|
||||
avail = static_cast<int>(Shared::Availability::online);
|
||||
}
|
||||
|
||||
settings.beginGroup("roster");
|
||||
QStringList entries = settings.allKeys();
|
||||
|
@ -486,13 +454,11 @@ void Application::readSettings()
|
|||
setState(Shared::Global::fromInt<Shared::Availability>(avail));
|
||||
createMainWindow();
|
||||
|
||||
if (settings.value("tray", false).toBool() && !settings.value("hideTray", false).toBool()) {
|
||||
if (settings.value("tray", false).toBool() && !settings.value("hideTray", false).toBool())
|
||||
createTrayIcon();
|
||||
}
|
||||
}
|
||||
|
||||
void Application::writeSettings()
|
||||
{
|
||||
void Application::writeSettings() {
|
||||
QSettings settings;
|
||||
settings.beginGroup("ui");
|
||||
settings.setValue("availability", static_cast<int>(availability));
|
||||
|
@ -501,9 +467,9 @@ void Application::writeSettings()
|
|||
settings.beginGroup("roster");
|
||||
for (const std::list<QString>& address : expandedPaths) {
|
||||
QString path = "";
|
||||
for (const QString& hop : address) {
|
||||
for (const QString& hop : address)
|
||||
path += hop + "/";
|
||||
}
|
||||
|
||||
path += "expanded";
|
||||
settings.setValue(path, true);
|
||||
}
|
||||
|
@ -513,54 +479,49 @@ void Application::writeSettings()
|
|||
}
|
||||
|
||||
void Application::requestPassword(const QString& account, bool authenticationError) {
|
||||
if (authenticationError) {
|
||||
if (authenticationError)
|
||||
dialogueQueue.addAction(account, DialogQueue::askCredentials);
|
||||
} else {
|
||||
else
|
||||
dialogueQueue.addAction(account, DialogQueue::askPassword);
|
||||
}
|
||||
|
||||
}
|
||||
void Application::onConversationClosed()
|
||||
{
|
||||
|
||||
void Application::onConversationClosed() {
|
||||
Conversation* conv = static_cast<Conversation*>(sender());
|
||||
Models::Roster::ElId id(conv->getAccount(), conv->getJid());
|
||||
Conversations::const_iterator itr = conversations.find(id);
|
||||
if (itr != conversations.end()) {
|
||||
if (itr != conversations.end())
|
||||
conversations.erase(itr);
|
||||
}
|
||||
|
||||
if (conv->isMuc) {
|
||||
Room* room = static_cast<Room*>(conv);
|
||||
if (!room->autoJoined()) {
|
||||
if (!room->autoJoined())
|
||||
emit setRoomJoined(id.account, id.name, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Application::changeSubscription(const Models::Roster::ElId& id, bool subscribe)
|
||||
{
|
||||
void Application::changeSubscription(const Models::Roster::ElId& id, bool subscribe) {
|
||||
Models::Item::Type type = roster.getContactType(id);
|
||||
|
||||
switch (type) {
|
||||
case Models::Item::contact:
|
||||
if (subscribe) {
|
||||
if (subscribe)
|
||||
emit subscribeContact(id.account, id.name, "");
|
||||
} else {
|
||||
else
|
||||
emit unsubscribeContact(id.account, id.name, "");
|
||||
}
|
||||
|
||||
break;
|
||||
case Models::Item::room:
|
||||
setRoomAutoJoin(id.account, id.name, subscribe);
|
||||
if (!isConverstationOpened(id)) {
|
||||
if (!isConverstationOpened(id))
|
||||
emit setRoomJoined(id.account, id.name, subscribe);
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Application::subscribeConversation(Conversation* conv)
|
||||
{
|
||||
void Application::subscribeConversation(Conversation* conv) {
|
||||
connect(conv, &Conversation::destroyed, this, &Application::onConversationClosed);
|
||||
connect(conv, &Conversation::sendMessage, this, &Application::onConversationMessage);
|
||||
connect(conv, &Conversation::replaceMessage, this, &Application::onConversationReplaceMessage);
|
||||
|
@ -568,8 +529,7 @@ void Application::subscribeConversation(Conversation* conv)
|
|||
connect(conv, &Conversation::notifyableMessage, this, &Application::notify);
|
||||
}
|
||||
|
||||
void Application::openConversation(const Models::Roster::ElId& id, const QString& resource)
|
||||
{
|
||||
void Application::openConversation(const Models::Roster::ElId& id, const QString& resource) {
|
||||
Conversations::const_iterator itr = conversations.find(id);
|
||||
Models::Account* acc = roster.getAccount(id.account);
|
||||
Conversation* conv = nullptr;
|
||||
|
@ -583,9 +543,8 @@ void Application::openConversation(const Models::Roster::ElId& id, const QString
|
|||
created = true;
|
||||
Models::Room* room = static_cast<Models::Room*>(el);
|
||||
conv = new Room(acc, room);
|
||||
if (!room->getJoined()) {
|
||||
if (!room->getJoined())
|
||||
emit setRoomJoined(id.account, id.name, true);
|
||||
}
|
||||
} else if (el->type == Models::Item::contact) {
|
||||
created = true;
|
||||
conv = new Chat(acc, static_cast<Models::Contact*>(el));
|
||||
|
@ -604,14 +563,12 @@ void Application::openConversation(const Models::Roster::ElId& id, const QString
|
|||
conv->raise();
|
||||
conv->activateWindow();
|
||||
|
||||
if (resource.size() > 0) {
|
||||
if (resource.size() > 0)
|
||||
conv->setPalResource(resource);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Application::onConversationMessage(const Shared::Message& msg)
|
||||
{
|
||||
void Application::onConversationMessage(const Shared::Message& msg) {
|
||||
Conversation* conv = static_cast<Conversation*>(sender());
|
||||
QString acc = conv->getAccount();
|
||||
|
||||
|
@ -619,8 +576,7 @@ void Application::onConversationMessage(const Shared::Message& msg)
|
|||
emit sendMessage(acc, msg);
|
||||
}
|
||||
|
||||
void Application::onConversationReplaceMessage(const QString& originalId, const Shared::Message& msg)
|
||||
{
|
||||
void Application::onConversationReplaceMessage(const QString& originalId, const Shared::Message& msg) {
|
||||
Conversation* conv = static_cast<Conversation*>(sender());
|
||||
QString acc = conv->getAccount();
|
||||
|
||||
|
@ -630,8 +586,7 @@ void Application::onConversationReplaceMessage(const QString& originalId, const
|
|||
emit replaceMessage(acc, originalId, msg);
|
||||
}
|
||||
|
||||
void Application::onConversationResend(const QString& id)
|
||||
{
|
||||
void Application::onConversationResend(const QString& id) {
|
||||
Conversation* conv = static_cast<Conversation*>(sender());
|
||||
QString acc = conv->getAccount();
|
||||
QString jid = conv->getJid();
|
||||
|
@ -649,8 +604,7 @@ void Application::onSquawkOpenedConversation() {
|
|||
}
|
||||
}
|
||||
|
||||
void Application::removeAccount(const QString& account)
|
||||
{
|
||||
void Application::removeAccount(const QString& account) {
|
||||
Conversations::const_iterator itr = conversations.begin();
|
||||
while (itr != conversations.end()) {
|
||||
if (itr->first.account == account) {
|
||||
|
@ -665,23 +619,20 @@ void Application::removeAccount(const QString& account)
|
|||
}
|
||||
}
|
||||
|
||||
if (squawk != nullptr && squawk->currentConversationId().account == account) {
|
||||
if (squawk != nullptr && squawk->currentConversationId().account == account)
|
||||
squawk->closeCurrentConversation();
|
||||
}
|
||||
|
||||
roster.removeAccount(account);
|
||||
}
|
||||
|
||||
void Application::changeAccount(const QString& account, const QMap<QString, QVariant>& data)
|
||||
{
|
||||
void Application::changeAccount(const QString& account, const QMap<QString, QVariant>& data) {
|
||||
for (QMap<QString, QVariant>::const_iterator itr = data.begin(), end = data.end(); itr != end; ++itr) {
|
||||
QString attr = itr.key();
|
||||
roster.updateAccount(account, attr, *itr);
|
||||
}
|
||||
}
|
||||
|
||||
void Application::addGroup(const QString& account, const QString& name)
|
||||
{
|
||||
void Application::addGroup(const QString& account, const QString& name) {
|
||||
roster.addGroup(account, name);
|
||||
|
||||
if (squawk != nullptr) {
|
||||
|
@ -692,9 +643,8 @@ void Application::addGroup(const QString& account, const QString& name)
|
|||
if (settings.value("expanded", false).toBool()) {
|
||||
QModelIndex ind = roster.getAccountIndex(account);
|
||||
squawk->expand(ind);
|
||||
if (settings.value(name + "/expanded", false).toBool()) {
|
||||
if (settings.value(name + "/expanded", false).toBool())
|
||||
squawk->expand(roster.getGroupIndex(account, name));
|
||||
}
|
||||
}
|
||||
settings.endGroup();
|
||||
settings.endGroup();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue