forked from blue/squawk
tooltips, status text fetching, window titles, app icon
This commit is contained in:
parent
3d15682b37
commit
e456ba980d
13 changed files with 206 additions and 15 deletions
|
@ -22,6 +22,7 @@
|
|||
#include <QScrollBar>
|
||||
#include <QTimer>
|
||||
#include <QGraphicsDropShadowEffect>
|
||||
#include <QFileDialog>
|
||||
|
||||
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<QFileDialog*>(sender());
|
||||
|
||||
qDebug() << d->selectedFiles();
|
||||
|
||||
d->deleteLater();
|
||||
}
|
||||
|
|
|
@ -75,6 +75,8 @@ protected slots:
|
|||
void onEnterPressed();
|
||||
void onMessagesResize(int amount);
|
||||
void onSliderValueChanged(int value);
|
||||
void onAttach();
|
||||
void onFileSelected();
|
||||
|
||||
private:
|
||||
enum Scroll {
|
||||
|
|
|
@ -95,18 +95,28 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="nameLabel">
|
||||
<property name="text">
|
||||
<string/>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="statusLabel">
|
||||
<property name="text">
|
||||
<string/>
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
</widget>
|
||||
<item>
|
||||
<widget class="QLabel" name="nameLabel">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="statusLabel">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_2">
|
||||
|
@ -192,7 +202,7 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>572</width>
|
||||
<height>111</height>
|
||||
<height>128</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
|
|
|
@ -20,6 +20,9 @@
|
|||
#include <QDebug>
|
||||
#include <QGraphicsDropShadowEffect>
|
||||
|
||||
const QRegExp urlReg("^(?!<img\\ssrc=\")((?:https?|ftp)://\\S+)");
|
||||
const QRegExp imgReg("((?:https?|ftp)://\\S+\\.(?:jpg|jpeg|png|svg|gif))");
|
||||
|
||||
MessageLine::MessageLine(QWidget* parent):
|
||||
QWidget(parent),
|
||||
messageIndex(),
|
||||
|
@ -75,7 +78,11 @@ MessageLine::Position MessageLine::message(const Shared::Message& msg)
|
|||
message->setBackgroundRole(QPalette::AlternateBase);
|
||||
message->setAutoFillBackground(true);
|
||||
|
||||
QLabel* body = new QLabel(msg.getBody());
|
||||
|
||||
QString bd = msg.getBody();
|
||||
//bd.replace(imgReg, "<img src=\"\\1\"/>");
|
||||
bd.replace(urlReg, "<a href=\"\\1\">\\1</a>");
|
||||
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);
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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<QString, Presence*> presences;
|
||||
Messages messages;
|
||||
unsigned int childMessages;
|
||||
QString status;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -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<Account*>(item);
|
||||
result = QString(Shared::connectionStateNames[acc->getAvailability()]);
|
||||
}
|
||||
break;
|
||||
case Item::contact: {
|
||||
Contact* contact = static_cast<Contact*>(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<Presence*>(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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue