Skip to content

Commit

Permalink
bookmarksmanager dialog. add separate field for muc name
Browse files Browse the repository at this point in the history
  • Loading branch information
Ri0n committed May 9, 2024
1 parent c1c38d3 commit b46d9c9
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 45 deletions.
91 changes: 52 additions & 39 deletions src/bookmarkmanage.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>539</width>
<height>257</height>
<height>289</height>
</rect>
</property>
<property name="windowTitle">
Expand All @@ -34,87 +34,100 @@
</item>
<item row="0" column="1">
<layout class="QGridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<item row="3" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Host:</string>
<string>Room:</string>
</property>
<property name="alignment">
<set>Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="host"/>
<item row="4" column="1">
<widget class="QLineEdit" name="nickname"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<item row="5" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Room:</string>
<string>Password:</string>
</property>
<property name="alignment">
<set>Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="room"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Nickname:</string>
<item row="7" column="1">
<spacer>
<property name="orientation">
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="alignment">
<set>Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter</set>
<property name="sizeHint" stdset="0">
<size>
<width>66</width>
<height>31</height>
</size>
</property>
</widget>
</spacer>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="nickname"/>
<item row="6" column="1">
<widget class="QComboBox" name="autoJoin"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_4">
<item row="3" column="1">
<widget class="QLineEdit" name="room"/>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Password:</string>
<string>Auto-join:</string>
</property>
<property name="alignment">
<set>Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter</set>
</property>
</widget>
</item>
<item row="3" column="1">
<item row="5" column="1">
<widget class="QLineEdit" name="password">
<property name="echoMode">
<enum>QLineEdit::EchoMode::Password</enum>
</property>
</widget>
</item>
<item row="5" column="1">
<spacer>
<property name="orientation">
<enum>Qt::Orientation::Vertical</enum>
<item row="2" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Host:</string>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>66</width>
<height>31</height>
</size>
<property name="alignment">
<set>Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter</set>
</property>
</spacer>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="host"/>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_5">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Auto-join:</string>
<string>Nickname:</string>
</property>
<property name="alignment">
<set>Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter</set>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QComboBox" name="autoJoin"/>
<item row="1" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Name:</string>
</property>
<property name="alignment">
<set>Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="mucName"/>
</item>
</layout>
</item>
Expand Down
11 changes: 9 additions & 2 deletions src/bookmarkmanagedlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ BookmarkManageDlg::BookmarkManageDlg(PsiAccount *account) : QDialog(), account_(
connect(ui_.listView->selectionModel(), SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
SLOT(selectionChanged(const QItemSelection &, const QItemSelection &)));

connect(ui_.mucName, SIGNAL(textEdited(const QString &)), SLOT(updateCurrentItem()));
connect(ui_.host, SIGNAL(textEdited(const QString &)), SLOT(updateCurrentItem()));
connect(ui_.room, SIGNAL(textEdited(const QString &)), SLOT(updateCurrentItem()));
connect(ui_.nickname, SIGNAL(textEdited(const QString &)), SLOT(updateCurrentItem()));
Expand Down Expand Up @@ -101,6 +102,7 @@ void BookmarkManageDlg::loadBookmarks()

for (const ConferenceBookmark &c : account_->bookmarkManager()->conferences()) {
QStandardItem *item = new QStandardItem(c.name());
item->setData(QVariant(c.name()), MucNameRole);
item->setData(QVariant(c.jid().full()), JidRole);
item->setData(QVariant(c.autoJoin()), AutoJoinRole);
item->setData(QVariant(c.nick()), NickRole);
Expand All @@ -111,7 +113,7 @@ void BookmarkManageDlg::loadBookmarks()

ConferenceBookmark BookmarkManageDlg::bookmarkFor(const QModelIndex &index) const
{
return ConferenceBookmark(index.data(Qt::DisplayRole).toString(), index.data(JidRole).toString(),
return ConferenceBookmark(index.data(MucNameRole).toString(), index.data(JidRole).toString(),
ConferenceBookmark::JoinType(index.data(AutoJoinRole).toInt()),
index.data(NickRole).toString(), index.data(PasswordRole).toString());
}
Expand Down Expand Up @@ -168,6 +170,8 @@ void BookmarkManageDlg::selectionChanged(const QItemSelection &selected, const Q
}

XMPP::Jid jid = XMPP::Jid(current.data(JidRole).toString());
ui_.mucName->setText(current.data(MucNameRole).toString());
ui_.mucName->setCursorPosition(0);
ui_.host->setText(jid.domain());
ui_.host->setCursorPosition(0);
ui_.room->setText(jid.node());
Expand All @@ -178,7 +182,7 @@ void BookmarkManageDlg::selectionChanged(const QItemSelection &selected, const Q
ui_.password->setCursorPosition(0);
ui_.autoJoin->setCurrentIndex(current.data(AutoJoinRole).toInt());
QList<QWidget *> editors;
editors << ui_.host << ui_.room << ui_.nickname << ui_.password << ui_.autoJoin;
editors << ui_.mucName << ui_.host << ui_.room << ui_.nickname << ui_.password << ui_.autoJoin;
for (QWidget *w : std::as_const(editors)) {
w->setEnabled(current.isValid());
}
Expand All @@ -195,6 +199,8 @@ void BookmarkManageDlg::updateCurrentItem()

QStandardItem *item = model_->item(currentIndex().row());
if (item) {
item->setData(ui_.mucName->text().isEmpty() ? jid().full() : ui_.mucName->text(), Qt::DisplayRole);
item->setData(ui_.mucName->text(), MucNameRole);
item->setData(QVariant(jid().full()), JidRole);
item->setData(QVariant(ui_.autoJoin->currentIndex()), AutoJoinRole);
item->setData(QVariant(ui_.nickname->text()), NickRole);
Expand Down Expand Up @@ -237,6 +243,7 @@ void BookmarkManageDlg::importBookmarks()
ConferenceBookmark c(elem);

QStandardItem *item = new QStandardItem(c.name());
item->setData(QVariant(c.name()), MucNameRole);
item->setData(QVariant(c.jid().full()), JidRole);
item->setData(QVariant(c.autoJoin()), AutoJoinRole);
item->setData(QVariant(c.nick()), NickRole);
Expand Down
9 changes: 5 additions & 4 deletions src/bookmarkmanagedlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ public slots:
private:
enum Role {
// DisplayRole / EditRole
JidRole = Qt::UserRole + 0,
AutoJoinRole = Qt::UserRole + 1,
NickRole = Qt::UserRole + 2,
PasswordRole = Qt::UserRole + 3
MucNameRole = Qt::UserRole + 0,
JidRole = Qt::UserRole + 2,
AutoJoinRole = Qt::UserRole + 3,
NickRole = Qt::UserRole + 4,
PasswordRole = Qt::UserRole + 5
};

void loadBookmarks();
Expand Down

0 comments on commit b46d9c9

Please sign in to comment.