From e456ba980da42cb6b874d6a915807eaf9059d332 Mon Sep 17 00:00:00 2001 From: blue Date: Fri, 21 Jun 2019 22:33:38 +0300 Subject: [PATCH] tooltips, status text fetching, window titles, app icon --- CMakeLists.txt | 5 ++-- global.h | 1 + resources/images/logo.svg | 30 +++++++++++++++++++++ resources/images/logo.svg~ | 30 +++++++++++++++++++++ resources/resources.qrc | 5 ++++ ui/conversation.cpp | 27 +++++++++++++++++++ ui/conversation.h | 2 ++ ui/conversation.ui | 32 ++++++++++++++-------- ui/messageline.cpp | 10 ++++++- ui/models/contact.cpp | 19 ++++++++++++- ui/models/contact.h | 3 +++ ui/models/roster.cpp | 55 ++++++++++++++++++++++++++++++++++++++ ui/squawk.cpp | 2 ++ 13 files changed, 206 insertions(+), 15 deletions(-) create mode 100644 resources/images/logo.svg create mode 100644 resources/images/logo.svg~ create mode 100644 resources/resources.qrc diff --git a/CMakeLists.txt b/CMakeLists.txt index a638787..b6f702c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,6 +8,8 @@ set(CMAKE_AUTOMOC ON) # Instruct CMake to create code from Qt designer ui files set(CMAKE_AUTOUIC ON) +set(CMAKE_AUTORCC ON) + find_package(Qt5Widgets CONFIG REQUIRED) set(squawk_SRC main.cpp @@ -16,8 +18,7 @@ set(squawk_SRC signalcatcher.cpp ) -# Tell CMake to create the helloworld executable -add_executable(squawk ${squawk_SRC}) +add_executable(squawk ${squawk_SRC} resources/resources.qrc) target_link_libraries(squawk Qt5::Widgets) add_subdirectory(ui) diff --git a/global.h b/global.h index e399907..7152180 100644 --- a/global.h +++ b/global.h @@ -52,6 +52,7 @@ static const std::deque availabilityThemeIcons = { static const std::deque availabilityNames = {"Online", "Away", "Absent", "Busy", "Chatty", "Offline"}; static const std::deque subscriptionStateThemeIcons = {"edit-none", "arrow-down-double", "arrow-up-double", "dialog-ok", "question"}; +static const std::deque subscriptionStateNames = {"None", "From", "To", "Both", "Unknown"}; QString generateUUID(); diff --git a/resources/images/logo.svg b/resources/images/logo.svg new file mode 100644 index 0000000..916ca13 --- /dev/null +++ b/resources/images/logo.svg @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/resources/images/logo.svg~ b/resources/images/logo.svg~ new file mode 100644 index 0000000..9254e49 --- /dev/null +++ b/resources/images/logo.svg~ @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/resources/resources.qrc b/resources/resources.qrc new file mode 100644 index 0000000..8d53a6f --- /dev/null +++ b/resources/resources.qrc @@ -0,0 +1,5 @@ + + + images/logo.svg + + diff --git a/ui/conversation.cpp b/ui/conversation.cpp index 3e7493a..2923c48 100644 --- a/ui/conversation.cpp +++ b/ui/conversation.cpp @@ -22,6 +22,7 @@ #include #include #include +#include Conversation::Conversation(Models::Contact* p_contact, QWidget* parent): QWidget(parent), @@ -42,10 +43,12 @@ Conversation::Conversation(Models::Contact* p_contact, QWidget* parent): setName(p_contact->getContactName()); setState(p_contact->getAvailability()); + setStatus(p_contact->getStatus()); connect(contact, SIGNAL(childChanged(Models::Item*, int, int)), this, SLOT(onContactChanged(Models::Item*, int, int))); connect(&ker, SIGNAL(enterPressed()), this, SLOT(onEnterPressed())); connect(m_ui->sendButton, SIGNAL(clicked(bool)), this, SLOT(onEnterPressed())); + //connect(m_ui->attachButton, SIGNAL(clicked(bool)), this, SLOT(onAttach())); m_ui->messageEditor->installEventFilter(&ker); @@ -99,6 +102,7 @@ void Conversation::applyVisualEffects() void Conversation::setName(const QString& name) { m_ui->nameLabel->setText(name); + setWindowTitle(name); line->setPalName(getJid(), name); } @@ -133,6 +137,9 @@ void Conversation::onContactChanged(Models::Item* item, int row, int col) case 3: setState(contact->getAvailability()); break; + case 5: + setStatus(contact->getStatus()); + break; } } } @@ -279,3 +286,23 @@ void Conversation::showEvent(QShowEvent* event) QWidget::showEvent(event); } + +void Conversation::onAttach() +{ + QFileDialog* d = new QFileDialog(this, "Chose a file to send"); + d->setFileMode(QFileDialog::ExistingFile); + + connect(d, SIGNAL(accepted()), this, SLOT(onFileSelected())); + connect(d, SIGNAL(rejected()), d, SLOT(deleteLater())); + + d->show(); +} + +void Conversation::onFileSelected() +{ + QFileDialog* d = static_cast(sender()); + + qDebug() << d->selectedFiles(); + + d->deleteLater(); +} diff --git a/ui/conversation.h b/ui/conversation.h index 310c0a0..0a5928f 100644 --- a/ui/conversation.h +++ b/ui/conversation.h @@ -75,6 +75,8 @@ protected slots: void onEnterPressed(); void onMessagesResize(int amount); void onSliderValueChanged(int value); + void onAttach(); + void onFileSelected(); private: enum Scroll { diff --git a/ui/conversation.ui b/ui/conversation.ui index 142df37..6c2669a 100644 --- a/ui/conversation.ui +++ b/ui/conversation.ui @@ -95,18 +95,28 @@ - - - + + + 0 - - - - - - + + 0 - + + + + + + + + + + + + + + + @@ -192,7 +202,7 @@ 0 0 572 - 111 + 128 diff --git a/ui/messageline.cpp b/ui/messageline.cpp index f421e72..104da62 100644 --- a/ui/messageline.cpp +++ b/ui/messageline.cpp @@ -20,6 +20,9 @@ #include #include +const QRegExp urlReg("^(?!setBackgroundRole(QPalette::AlternateBase); message->setAutoFillBackground(true); - QLabel* body = new QLabel(msg.getBody()); + + QString bd = msg.getBody(); + //bd.replace(imgReg, ""); + bd.replace(urlReg, "\\1"); + QLabel* body = new QLabel(bd); body->setTextInteractionFlags(body->textInteractionFlags() | Qt::TextSelectableByMouse); QLabel* sender = new QLabel(); QLabel* time = new QLabel(msg.getTime().toLocalTime().toString()); @@ -89,6 +96,7 @@ MessageLine::Position MessageLine::message(const Shared::Message& msg) sender->setFont(f); body->setWordWrap(true); + body->setOpenExternalLinks(true); vBox->addWidget(sender); vBox->addWidget(body); diff --git a/ui/models/contact.cpp b/ui/models/contact.cpp index a68bd82..53c68a5 100644 --- a/ui/models/contact.cpp +++ b/ui/models/contact.cpp @@ -67,9 +67,22 @@ void Models::Contact::setAvailability(Shared::Availability p_state) } } +QString Models::Contact::getStatus() const +{ + return status; +} + +void Models::Contact::setStatus(const QString& p_state) +{ + if (status != p_state) { + status = p_state; + changed(5); + } +} + int Models::Contact::columnCount() const { - return 5; + return 6; } QVariant Models::Contact::data(int column) const @@ -85,6 +98,8 @@ QVariant Models::Contact::data(int column) const return availability; case 4: return getMessagesCount(); + case 5: + return getStatus(); default: return QVariant(); } @@ -161,8 +176,10 @@ void Models::Contact::refresh() if (presence != 0) { setAvailability(presence->getAvailability()); + setStatus(presence->getStatus()); } else { setAvailability(Shared::offline); + setStatus(""); } if (childMessages != count) { diff --git a/ui/models/contact.h b/ui/models/contact.h index 40905d2..6370cb4 100644 --- a/ui/models/contact.h +++ b/ui/models/contact.h @@ -37,6 +37,7 @@ public: QString getAccountJid() const; QString getAccountResource() const; QString getContactName() const; + QString getStatus() const; void addMessage(const Shared::Message& data); unsigned int getMessagesCount() const; @@ -56,6 +57,7 @@ protected: void setState(Shared::SubscriptionState p_state); void setState(unsigned int p_state); void setJid(const QString p_jid); + void setStatus(const QString& p_state); private: QString jid; @@ -64,6 +66,7 @@ private: QMap presences; Messages messages; unsigned int childMessages; + QString status; }; } diff --git a/ui/models/roster.cpp b/ui/models/roster.cpp index d360a4d..fa5eb9e 100644 --- a/ui/models/roster.cpp +++ b/ui/models/roster.cpp @@ -93,6 +93,61 @@ QVariant Models::Roster::data (const QModelIndex& index, int role) const default: break; } + break; + case Qt::ToolTipRole: + switch (item->type) { + case Item::account: { + Account* acc = static_cast(item); + result = QString(Shared::connectionStateNames[acc->getAvailability()]); + } + break; + case Item::contact: { + Contact* contact = static_cast(item); + QString str = QString(""); + int mc = contact->getMessagesCount(); + if (mc > 0) { + str += QString("New messages: ") + std::to_string(mc).c_str() + "\n"; + } + Shared::SubscriptionState ss = contact->getState(); + if (ss == Shared::both) { + Shared::Availability av = contact->getAvailability(); + str += "Availability: " + Shared::availabilityNames[av]; + if (av != Shared::offline) { + QString s = contact->getStatus(); + if (s.size() > 0) { + str += "\nStatus: " + s; + } + } + str += "\nSubscription: " + Shared::subscriptionStateNames[ss]; + } else { + str += "Subscription: " + Shared::subscriptionStateNames[ss]; + } + + result = str; + } + break; + case Item::presence: { + Presence* contact = static_cast(item); + QString str = QString(""); + int mc = contact->getMessagesCount(); + if (mc > 0) { + str += QString("New messages: ") + std::to_string(mc).c_str() + "\n"; + } + Shared::Availability av = contact->getAvailability(); + str += "Availability: " + Shared::availabilityNames[av]; + QString s = contact->getStatus(); + if (s.size() > 0) { + str += "\nStatus: " + s; + } + + result = str; + } + break; + default: + result = ""; + break; + } + break; default: break; } diff --git a/ui/squawk.cpp b/ui/squawk.cpp index 5cc28f6..e8dae81 100644 --- a/ui/squawk.cpp +++ b/ui/squawk.cpp @@ -12,6 +12,8 @@ Squawk::Squawk(QWidget *parent) : contextMenu(new QMenu()), dbus("org.freedesktop.Notifications", "/org/freedesktop/Notifications", "org.freedesktop.Notifications", QDBusConnection::sessionBus()) { + setWindowIcon(QIcon(":images/logo.svg")); + m_ui->setupUi(this); m_ui->roster->setModel(&rosterModel); m_ui->roster->setContextMenuPolicy(Qt::CustomContextMenu);