forked from blue/squawk
first attempt to make About window
This commit is contained in:
parent
4baa3bccbf
commit
27377e0ec5
10 changed files with 354 additions and 52 deletions
|
@ -24,16 +24,17 @@
|
|||
Squawk::Squawk(QWidget *parent) :
|
||||
QMainWindow(parent),
|
||||
m_ui(new Ui::Squawk),
|
||||
accounts(0),
|
||||
preferences(0),
|
||||
accounts(nullptr),
|
||||
preferences(nullptr),
|
||||
about(nullptr),
|
||||
rosterModel(),
|
||||
conversations(),
|
||||
contextMenu(new QMenu()),
|
||||
dbus("org.freedesktop.Notifications", "/org/freedesktop/Notifications", "org.freedesktop.Notifications", QDBusConnection::sessionBus()),
|
||||
vCards(),
|
||||
requestedAccountsForPasswords(),
|
||||
prompt(0),
|
||||
currentConversation(0),
|
||||
prompt(nullptr),
|
||||
currentConversation(nullptr),
|
||||
restoreSelection(),
|
||||
needToRestore(false)
|
||||
{
|
||||
|
@ -72,6 +73,7 @@ Squawk::Squawk(QWidget *parent) :
|
|||
connect(&rosterModel, &Models::Roster::fileDownloadRequest, this, &Squawk::fileDownloadRequest);
|
||||
connect(&rosterModel, &Models::Roster::localPathInvalid, this, &Squawk::localPathInvalid);
|
||||
connect(contextMenu, &QMenu::aboutToHide, this, &Squawk::onContextAboutToHide);
|
||||
connect(m_ui->actionAboutSquawk, &QAction::triggered, this, &Squawk::onAboutSquawkCalled);
|
||||
//m_ui->mainToolBar->addWidget(m_ui->comboBox);
|
||||
|
||||
if (testAttribute(Qt::WA_TranslucentBackground)) {
|
||||
|
@ -101,7 +103,7 @@ Squawk::~Squawk() {
|
|||
|
||||
void Squawk::onAccounts()
|
||||
{
|
||||
if (accounts == 0) {
|
||||
if (accounts == nullptr) {
|
||||
accounts = new Accounts(rosterModel.accountsModel);
|
||||
accounts->setAttribute(Qt::WA_DeleteOnClose);
|
||||
connect(accounts, &Accounts::destroyed, this, &Squawk::onAccountsClosed);
|
||||
|
@ -121,7 +123,7 @@ void Squawk::onAccounts()
|
|||
|
||||
void Squawk::onPreferences()
|
||||
{
|
||||
if (preferences == 0) {
|
||||
if (preferences == nullptr) {
|
||||
preferences = new Settings();
|
||||
preferences->setAttribute(Qt::WA_DeleteOnClose);
|
||||
connect(preferences, &Settings::destroyed, this, &Squawk::onPreferencesClosed);
|
||||
|
@ -189,12 +191,15 @@ void Squawk::onJoinConferenceAccepted()
|
|||
|
||||
void Squawk::closeEvent(QCloseEvent* event)
|
||||
{
|
||||
if (accounts != 0) {
|
||||
if (accounts != nullptr) {
|
||||
accounts->close();
|
||||
}
|
||||
if (preferences != 0) {
|
||||
if (preferences != nullptr) {
|
||||
preferences->close();
|
||||
}
|
||||
if (about != nullptr) {
|
||||
about->close();
|
||||
}
|
||||
|
||||
for (Conversations::const_iterator itr = conversations.begin(), end = conversations.end(); itr != end; ++itr) {
|
||||
disconnect(itr->second, &Conversation::destroyed, this, &Squawk::onConversationClosed);
|
||||
|
@ -214,12 +219,12 @@ void Squawk::closeEvent(QCloseEvent* event)
|
|||
|
||||
void Squawk::onAccountsClosed()
|
||||
{
|
||||
accounts = 0;
|
||||
accounts = nullptr;
|
||||
}
|
||||
|
||||
void Squawk::onPreferencesClosed()
|
||||
{
|
||||
preferences = 0;
|
||||
preferences = nullptr;
|
||||
}
|
||||
|
||||
void Squawk::newAccount(const QMap<QString, QVariant>& account)
|
||||
|
@ -342,10 +347,10 @@ void Squawk::onRosterItemDoubleClicked(const QModelIndex& item)
|
|||
if (node->type == Models::Item::reference) {
|
||||
node = static_cast<Models::Reference*>(node)->dereference();
|
||||
}
|
||||
Models::Contact* contact = 0;
|
||||
Models::Room* room = 0;
|
||||
Models::Contact* contact = nullptr;
|
||||
Models::Room* room = nullptr;
|
||||
QString res;
|
||||
Models::Roster::ElId* id = 0;
|
||||
Models::Roster::ElId* id = nullptr;
|
||||
switch (node->type) {
|
||||
case Models::Item::contact:
|
||||
contact = static_cast<Models::Contact*>(node);
|
||||
|
@ -365,17 +370,17 @@ void Squawk::onRosterItemDoubleClicked(const QModelIndex& item)
|
|||
break;
|
||||
}
|
||||
|
||||
if (id != 0) {
|
||||
if (id != nullptr) {
|
||||
Conversations::const_iterator itr = conversations.find(*id);
|
||||
Models::Account* acc = rosterModel.getAccount(id->account);
|
||||
Conversation* conv = 0;
|
||||
Conversation* conv = nullptr;
|
||||
bool created = false;
|
||||
if (itr != conversations.end()) {
|
||||
conv = itr->second;
|
||||
} else if (contact != 0) {
|
||||
} else if (contact != nullptr) {
|
||||
created = true;
|
||||
conv = new Chat(acc, contact);
|
||||
} else if (room != 0) {
|
||||
} else if (room != nullptr) {
|
||||
created = true;
|
||||
conv = new Room(acc, room);
|
||||
|
||||
|
@ -384,7 +389,7 @@ void Squawk::onRosterItemDoubleClicked(const QModelIndex& item)
|
|||
}
|
||||
}
|
||||
|
||||
if (conv != 0) {
|
||||
if (conv != nullptr) {
|
||||
if (created) {
|
||||
conv->setAttribute(Qt::WA_DeleteOnClose);
|
||||
subscribeConversation(conv);
|
||||
|
@ -543,9 +548,9 @@ void Squawk::removeAccount(const QString& account)
|
|||
}
|
||||
}
|
||||
|
||||
if (currentConversation != 0 && currentConversation->getAccount() == account) {
|
||||
if (currentConversation != nullptr && currentConversation->getAccount() == account) {
|
||||
currentConversation->deleteLater();
|
||||
currentConversation = 0;
|
||||
currentConversation = nullptr;
|
||||
m_ui->filler->show();
|
||||
}
|
||||
|
||||
|
@ -710,7 +715,7 @@ void Squawk::onRosterContextMenu(const QPoint& point)
|
|||
connect(unsub, &QAction::triggered, [this, id]() {
|
||||
emit setRoomAutoJoin(id.account, id.name, false);
|
||||
if (conversations.find(id) == conversations.end()
|
||||
&& (currentConversation == 0 || currentConversation->getId() != id)
|
||||
&& (currentConversation == nullptr || currentConversation->getId() != id)
|
||||
) { //to leave the room if it's not opened in a conversation window
|
||||
emit setRoomJoined(id.account, id.name, false);
|
||||
}
|
||||
|
@ -721,7 +726,7 @@ void Squawk::onRosterContextMenu(const QPoint& point)
|
|||
connect(unsub, &QAction::triggered, [this, id]() {
|
||||
emit setRoomAutoJoin(id.account, id.name, true);
|
||||
if (conversations.find(id) == conversations.end()
|
||||
&& (currentConversation == 0 || currentConversation->getId() != id)
|
||||
&& (currentConversation == nullptr || currentConversation->getId() != id)
|
||||
) { //to join the room if it's not already joined
|
||||
emit setRoomJoined(id.account, id.name, true);
|
||||
}
|
||||
|
@ -928,7 +933,7 @@ void Squawk::requestPassword(const QString& account)
|
|||
|
||||
void Squawk::checkNextAccountForPassword()
|
||||
{
|
||||
if (prompt == 0 && requestedAccountsForPasswords.size() > 0) {
|
||||
if (prompt == nullptr && requestedAccountsForPasswords.size() > 0) {
|
||||
prompt = new QInputDialog(this);
|
||||
QString accName = requestedAccountsForPasswords.front();
|
||||
connect(prompt, &QDialog::accepted, this, &Squawk::onPasswordPromptAccepted);
|
||||
|
@ -951,7 +956,7 @@ void Squawk::onPasswordPromptAccepted()
|
|||
void Squawk::onPasswordPromptDone()
|
||||
{
|
||||
prompt->deleteLater();
|
||||
prompt = 0;
|
||||
prompt = nullptr;
|
||||
requestedAccountsForPasswords.pop_front();
|
||||
checkNextAccountForPassword();
|
||||
}
|
||||
|
@ -986,10 +991,10 @@ void Squawk::onRosterSelectionChanged(const QModelIndex& current, const QModelIn
|
|||
if (node->type == Models::Item::reference) {
|
||||
node = static_cast<Models::Reference*>(node)->dereference();
|
||||
}
|
||||
Models::Contact* contact = 0;
|
||||
Models::Room* room = 0;
|
||||
Models::Contact* contact = nullptr;
|
||||
Models::Room* room = nullptr;
|
||||
QString res;
|
||||
Models::Roster::ElId* id = 0;
|
||||
Models::Roster::ElId* id = nullptr;
|
||||
bool hasContext = true;
|
||||
switch (node->type) {
|
||||
case Models::Item::contact:
|
||||
|
@ -1018,7 +1023,7 @@ void Squawk::onRosterSelectionChanged(const QModelIndex& current, const QModelIn
|
|||
}
|
||||
|
||||
if (hasContext && QGuiApplication::mouseButtons() & Qt::RightButton) {
|
||||
if (id != 0) {
|
||||
if (id != nullptr) {
|
||||
delete id;
|
||||
}
|
||||
needToRestore = true;
|
||||
|
@ -1026,10 +1031,10 @@ void Squawk::onRosterSelectionChanged(const QModelIndex& current, const QModelIn
|
|||
return;
|
||||
}
|
||||
|
||||
if (id != 0) {
|
||||
if (currentConversation != 0) {
|
||||
if (id != nullptr) {
|
||||
if (currentConversation != nullptr) {
|
||||
if (currentConversation->getId() == *id) {
|
||||
if (contact != 0) {
|
||||
if (contact != nullptr) {
|
||||
currentConversation->setPalResource(res);
|
||||
}
|
||||
return;
|
||||
|
@ -1041,9 +1046,9 @@ void Squawk::onRosterSelectionChanged(const QModelIndex& current, const QModelIn
|
|||
}
|
||||
|
||||
Models::Account* acc = rosterModel.getAccount(id->account);
|
||||
if (contact != 0) {
|
||||
if (contact != nullptr) {
|
||||
currentConversation = new Chat(acc, contact);
|
||||
} else if (room != 0) {
|
||||
} else if (room != nullptr) {
|
||||
currentConversation = new Room(acc, room);
|
||||
|
||||
if (!room->getJoined()) {
|
||||
|
@ -1064,16 +1069,16 @@ void Squawk::onRosterSelectionChanged(const QModelIndex& current, const QModelIn
|
|||
|
||||
delete id;
|
||||
} else {
|
||||
if (currentConversation != 0) {
|
||||
if (currentConversation != nullptr) {
|
||||
currentConversation->deleteLater();
|
||||
currentConversation = 0;
|
||||
currentConversation = nullptr;
|
||||
m_ui->filler->show();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (currentConversation != 0) {
|
||||
if (currentConversation != nullptr) {
|
||||
currentConversation->deleteLater();
|
||||
currentConversation = 0;
|
||||
currentConversation = nullptr;
|
||||
m_ui->filler->show();
|
||||
}
|
||||
}
|
||||
|
@ -1086,3 +1091,22 @@ void Squawk::onContextAboutToHide()
|
|||
m_ui->roster->selectionModel()->setCurrentIndex(restoreSelection, QItemSelectionModel::ClearAndSelect);
|
||||
}
|
||||
}
|
||||
|
||||
void Squawk::onAboutSquawkCalled()
|
||||
{
|
||||
if (about == nullptr) {
|
||||
about = new About();
|
||||
about->setAttribute(Qt::WA_DeleteOnClose);
|
||||
connect(about, &Settings::destroyed, this, &Squawk::onAboutSquawkClosed);
|
||||
about->show();
|
||||
} else {
|
||||
about->raise();
|
||||
about->activateWindow();
|
||||
about->show();
|
||||
}
|
||||
}
|
||||
|
||||
void Squawk::onAboutSquawkClosed()
|
||||
{
|
||||
about = nullptr;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue