Changeset View
Changeset View
Standalone View
Standalone View
src/widgets/channellist/channellistwidget.cpp
Show First 20 Lines • Show All 48 Lines • ▼ Show 20 Line(s) | 44 | { | |||
---|---|---|---|---|---|
49 | mSearchRoom = new QLineEdit(this); | 49 | mSearchRoom = new QLineEdit(this); | ||
50 | // dummy action just for getting the icon) | 50 | // dummy action just for getting the icon) | ||
51 | mSearchRoom->addAction(QIcon::fromTheme(QStringLiteral("view-filter")), QLineEdit::LeadingPosition); | 51 | mSearchRoom->addAction(QIcon::fromTheme(QStringLiteral("view-filter")), QLineEdit::LeadingPosition); | ||
52 | mSearchRoom->setObjectName(QStringLiteral("mSearchRoom")); | 52 | mSearchRoom->setObjectName(QStringLiteral("mSearchRoom")); | ||
53 | mSearchRoom->setPlaceholderText(i18n("Search Rooms (CTRL + K)")); | 53 | mSearchRoom->setPlaceholderText(i18n("Search Rooms (CTRL + K)")); | ||
54 | mSearchRoom->setClearButtonEnabled(true); | 54 | mSearchRoom->setClearButtonEnabled(true); | ||
55 | mSearchRoom->installEventFilter(this); | 55 | mSearchRoom->installEventFilter(this); | ||
56 | mainLayout->addWidget(mSearchRoom); | 56 | mainLayout->addWidget(mSearchRoom); | ||
57 | connect(mSearchRoom, &QLineEdit::textChanged, this, &ChannelListWidget::slotSearchRoomTextChanged); | | |||
58 | 57 | | |||
59 | mChannelView = new ChannelListView(this); | 58 | mChannelView = new ChannelListView(this); | ||
60 | mChannelView->setObjectName(QStringLiteral("mChannelView")); | 59 | mChannelView->setObjectName(QStringLiteral("mChannelView")); | ||
61 | mainLayout->addWidget(mChannelView); | 60 | mainLayout->addWidget(mChannelView); | ||
62 | connect(mChannelView, &ChannelListView::roomSelected, this, &ChannelListWidget::roomSelected); | 61 | connect(mChannelView, &ChannelListView::channelActivated, this, &ChannelListWidget::channelActivated); | ||
62 | connect(mSearchRoom, &QLineEdit::textChanged, mChannelView, &ChannelListView::setFilterString); | ||||
63 | 63 | | |||
64 | auto *statusComboBoxLayout = new QHBoxLayout; | 64 | auto *statusComboBoxLayout = new QHBoxLayout; | ||
65 | mainLayout->addLayout(statusComboBoxLayout); | 65 | mainLayout->addLayout(statusComboBoxLayout); | ||
66 | QLabel *label = new QLabel(i18n("Status:"), this); | 66 | QLabel *label = new QLabel(i18n("Status:"), this); | ||
67 | label->setObjectName(QStringLiteral("label")); | 67 | label->setObjectName(QStringLiteral("label")); | ||
68 | statusComboBoxLayout->addWidget(label); | 68 | statusComboBoxLayout->addWidget(label); | ||
69 | 69 | | |||
70 | mStatusComboBox = new StatusCombobox(true, this); | 70 | mStatusComboBox = new StatusCombobox(true, this); | ||
Show All 10 Lines | |||||
81 | addAction(searchRoomAction); // TODO: Add to MainWindow's action collection instead? | 81 | addAction(searchRoomAction); // TODO: Add to MainWindow's action collection instead? | ||
82 | //END: Actions | 82 | //END: Actions | ||
83 | } | 83 | } | ||
84 | 84 | | |||
85 | ChannelListWidget::~ChannelListWidget() | 85 | ChannelListWidget::~ChannelListWidget() | ||
86 | { | 86 | { | ||
87 | } | 87 | } | ||
88 | 88 | | |||
89 | void ChannelListWidget::clearFilterChannel() | | |||
90 | { | | |||
91 | if (auto *model = mChannelView->model()) { | | |||
92 | model->setFilterString(QString()); | | |||
93 | mSearchRoom->clear(); | | |||
94 | } | | |||
95 | } | | |||
96 | | ||||
97 | void ChannelListWidget::setCurrentRocketChatAccount(RocketChatAccount *account) | 89 | void ChannelListWidget::setCurrentRocketChatAccount(RocketChatAccount *account) | ||
98 | { | 90 | { | ||
99 | clearFilterChannel(); | | |||
100 | if (mCurrentRocketChatAccount) { | 91 | if (mCurrentRocketChatAccount) { | ||
101 | disconnect(mCurrentRocketChatAccount, nullptr, this, nullptr); | 92 | disconnect(mCurrentRocketChatAccount, nullptr, this, nullptr); | ||
102 | } | 93 | } | ||
103 | mCurrentRocketChatAccount = account; | 94 | mCurrentRocketChatAccount = account; | ||
104 | connect(mCurrentRocketChatAccount, &RocketChatAccount::accountInitialized, this, &ChannelListWidget::slotAccountInitialized); | 95 | connect(mCurrentRocketChatAccount, &RocketChatAccount::accountInitialized, this, &ChannelListWidget::slotAccountInitialized); | ||
105 | connect(mCurrentRocketChatAccount, &RocketChatAccount::userStatusUpdated, this, &ChannelListWidget::setUserStatusUpdated); | 96 | connect(mCurrentRocketChatAccount, &RocketChatAccount::userStatusUpdated, this, &ChannelListWidget::setUserStatusUpdated); | ||
106 | connect(mCurrentRocketChatAccount, &RocketChatAccount::openLinkRequested, this, &ChannelListWidget::slotOpenLinkRequested); | 97 | connect(mCurrentRocketChatAccount, &RocketChatAccount::openLinkRequested, this, &ChannelListWidget::slotOpenLinkRequested); | ||
107 | connect(mCurrentRocketChatAccount, &RocketChatAccount::selectRoomByRoomNameRequested, mChannelView, &ChannelListView::selectChannelByRoomNameRequested); | 98 | connect(mCurrentRocketChatAccount, &RocketChatAccount::selectRoomByRoomNameRequested, mChannelView, &ChannelListView::activateChannelByRoomName); | ||
108 | connect(mCurrentRocketChatAccount, &RocketChatAccount::selectRoomByRoomIdRequested, mChannelView, &ChannelListView::selectChannelRequested); | 99 | connect(mCurrentRocketChatAccount, &RocketChatAccount::selectRoomByRoomIdRequested, mChannelView, &ChannelListView::activateChannelById); | ||
109 | 100 | | |||
110 | mChannelView->setModel(mCurrentRocketChatAccount->roomFilterProxyModel()); | | |||
111 | mStatusComboBox->blockSignals(true); | 101 | mStatusComboBox->blockSignals(true); | ||
112 | mStatusComboBox->setStatus(mCurrentRocketChatAccount->presenceStatus()); | 102 | mStatusComboBox->setStatus(mCurrentRocketChatAccount->presenceStatus()); | ||
113 | mStatusComboBox->blockSignals(false); | 103 | mStatusComboBox->blockSignals(false); | ||
114 | } | 104 | } | ||
115 | 105 | | |||
116 | ChannelListView *ChannelListWidget::channelListView() const | 106 | ChannelListView *ChannelListWidget::channelListView() const | ||
117 | { | 107 | { | ||
118 | return mChannelView; | 108 | return mChannelView; | ||
119 | } | 109 | } | ||
120 | 110 | | |||
121 | bool ChannelListWidget::eventFilter(QObject *object, QEvent *event) | 111 | bool ChannelListWidget::eventFilter(QObject *object, QEvent *event) | ||
122 | { | 112 | { | ||
123 | if (object == mSearchRoom && event->type() == QEvent::KeyPress) { | 113 | if (object == mSearchRoom && event->type() == QEvent::KeyPress) { | ||
124 | const auto *model = mChannelView->model(); | | |||
125 | const auto *keyEvent = static_cast<QKeyEvent *>(event); | 114 | const auto *keyEvent = static_cast<QKeyEvent *>(event); | ||
126 | const int keyValue = keyEvent->key(); | 115 | const int keyValue = keyEvent->key(); | ||
127 | if (keyValue == Qt::Key_Return || keyValue == Qt::Key_Enter) { | 116 | switch (keyValue) | ||
117 | { | ||||
118 | case Qt::Key_Return: | ||||
119 | case Qt::Key_Enter: | ||||
120 | { | ||||
128 | const auto selectedIndex = mChannelView->selectionModel()->currentIndex(); | 121 | const auto selectedIndex = mChannelView->selectionModel()->currentIndex(); | ||
129 | if (selectedIndex.isValid()) { | 122 | if (selectedIndex.isValid()) { | ||
130 | mChannelView->channelSelected(selectedIndex); | 123 | mChannelView->activateChannel(selectedIndex); | ||
131 | mSearchRoom->setText({}); | 124 | mSearchRoom->setText({}); | ||
132 | } | 125 | } | ||
133 | } else if (keyValue == Qt::Key_Up || keyValue == Qt::Key_Down) { | | |||
134 | const QModelIndex currentIndex = mChannelView->selectionModel()->currentIndex(); | | |||
135 | int selectRow = -1; | | |||
136 | if (keyValue == Qt::Key_Up) { | | |||
137 | if (!currentIndex.isValid()) { | | |||
138 | selectRow = model->rowCount() - 1; | | |||
139 | } else if (currentIndex.row()-1 >= 0) { | | |||
140 | selectRow = currentIndex.row() - 1; | | |||
141 | } | | |||
142 | } else { // Qt::Key_Down | | |||
143 | if (!currentIndex.isValid()) { | | |||
144 | selectRow = 0; | | |||
145 | } else if (currentIndex.row()+1 < model->rowCount()) { | | |||
146 | selectRow = currentIndex.row() + 1; | | |||
147 | } | | |||
148 | } | | |||
149 | | ||||
150 | if (selectRow != -1) { | | |||
151 | mChannelView->selectionModel()->setCurrentIndex(model->index(selectRow, 0), QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows); | | |||
152 | } | 126 | } | ||
153 | return true; // eat event | 127 | break; | ||
128 | case Qt::Key_Up: | ||||
129 | mChannelView->moveSelectionUp(); | ||||
130 | return true; | ||||
131 | case Qt::Key_Down: | ||||
132 | mChannelView->moveSelectionDown(); | ||||
133 | return true; | ||||
154 | } | 134 | } | ||
155 | } | 135 | } | ||
156 | 136 | | |||
157 | return QWidget::eventFilter(object, event); | 137 | return QWidget::eventFilter(object, event); | ||
158 | } | 138 | } | ||
159 | 139 | | |||
160 | void ChannelListWidget::slotAccountInitialized() | 140 | void ChannelListWidget::slotAccountInitialized() | ||
161 | { | 141 | { | ||
162 | mChannelView->selectChannelRequested(mCurrentRocketChatAccount->settings()->lastSelectedRoom()); | 142 | mChannelView->activateChannelById(mCurrentRocketChatAccount->settings()->lastSelectedRoom()); | ||
163 | } | 143 | } | ||
164 | 144 | | |||
165 | void ChannelListWidget::setUserStatusUpdated(User::PresenceStatus status, const QString &accountName) | 145 | void ChannelListWidget::setUserStatusUpdated(User::PresenceStatus status, const QString &accountName) | ||
166 | { | 146 | { | ||
167 | if (mCurrentRocketChatAccount->accountName() == accountName) { | 147 | if (mCurrentRocketChatAccount->accountName() == accountName) { | ||
168 | mStatusComboBox->setStatus(status); | 148 | mStatusComboBox->setStatus(status); | ||
169 | } | 149 | } | ||
170 | } | 150 | } | ||
Show All 16 Lines | 164 | } else { | |||
187 | return; | 167 | return; | ||
188 | } | 168 | } | ||
189 | } | 169 | } | ||
190 | mCurrentRocketChatAccount->setDefaultStatus(status, messageStatus); | 170 | mCurrentRocketChatAccount->setDefaultStatus(status, messageStatus); | ||
191 | } | 171 | } | ||
192 | 172 | | |||
193 | void ChannelListWidget::slotSearchRoomTextChanged() | 173 | void ChannelListWidget::slotSearchRoomTextChanged() | ||
194 | { | 174 | { | ||
195 | mChannelView->model()->setFilterString(mSearchRoom->text()); | 175 | mChannelView->setFilterString(mSearchRoom->text()); | ||
196 | } | 176 | } | ||
197 | 177 | | |||
198 | void ChannelListWidget::slotOpenLinkRequested(const QString &link) | 178 | void ChannelListWidget::slotOpenLinkRequested(const QString &link) | ||
199 | { | 179 | { | ||
200 | if (link.startsWith(QLatin1String("ruqola:"))) { | 180 | if (link.startsWith(QLatin1String("ruqola:"))) { | ||
201 | const QString roomOrUser = RuqolaUtils::self()->extractRoomUserFromUrl(link); | 181 | const QString roomOrUser = RuqolaUtils::self()->extractRoomUserFromUrl(link); | ||
202 | const QModelIndex selectedIndex = mChannelView->selectionModel()->currentIndex(); | 182 | const QModelIndex selectedIndex = mChannelView->selectionModel()->currentIndex(); | ||
203 | if (selectedIndex.isValid()) { | 183 | if (selectedIndex.isValid()) { | ||
204 | const QString currentRoomId = selectedIndex.data(RoomModel::RoomName).toString(); | 184 | const QString currentRoomId = selectedIndex.data(RoomModel::RoomName).toString(); | ||
205 | if (roomOrUser == currentRoomId) { | 185 | if (roomOrUser == currentRoomId) { | ||
206 | return; | 186 | return; | ||
207 | } | 187 | } | ||
208 | } | 188 | } | ||
209 | if (link.startsWith(QLatin1String("ruqola:/room/"))) { | 189 | if (link.startsWith(QLatin1String("ruqola:/room/"))) { | ||
210 | if (!mChannelView->selectChannelByRoomNameRequested(roomOrUser)) { | 190 | if (!mChannelView->activateChannelByRoomName(roomOrUser)) { | ||
211 | mCurrentRocketChatAccount->openChannel(roomOrUser, RocketChatAccount::ChannelTypeInfo::RoomName); | 191 | mCurrentRocketChatAccount->openChannel(roomOrUser, RocketChatAccount::ChannelTypeInfo::RoomName); | ||
212 | } | 192 | } | ||
213 | } else if (link.startsWith(QLatin1String("ruqola:/user/"))) { | 193 | } else if (link.startsWith(QLatin1String("ruqola:/user/"))) { | ||
214 | if (roomOrUser == QLatin1String("here") || roomOrUser == QLatin1String("all")) { | 194 | if (roomOrUser == QLatin1String("here") || roomOrUser == QLatin1String("all")) { | ||
215 | return; | 195 | return; | ||
216 | } | 196 | } | ||
217 | if (!mChannelView->selectChannelByRoomNameRequested(roomOrUser)) { | 197 | if (!mChannelView->activateChannelByRoomName(roomOrUser)) { | ||
218 | if (roomOrUser != mCurrentRocketChatAccount->userName()) { | 198 | if (roomOrUser != mCurrentRocketChatAccount->userName()) { | ||
219 | if (KMessageBox::Yes == KMessageBox::questionYesNo(this, i18n("Do you want to open direct conversation with %1", roomOrUser))) { | 199 | if (KMessageBox::Yes == KMessageBox::questionYesNo(this, i18n("Do you want to open direct conversation with %1", roomOrUser))) { | ||
220 | mCurrentRocketChatAccount->openDirectChannel(roomOrUser); | 200 | mCurrentRocketChatAccount->openDirectChannel(roomOrUser); | ||
221 | } | 201 | } | ||
222 | } | 202 | } | ||
223 | } | 203 | } | ||
224 | } else if (link == QLatin1String("ruqola:/jitsicall/")) { | 204 | } else if (link == QLatin1String("ruqola:/jitsicall/")) { | ||
225 | const QModelIndex jitsiSelectedIndex = mChannelView->selectionModel()->currentIndex(); | 205 | const QModelIndex jitsiSelectedIndex = mChannelView->selectionModel()->currentIndex(); | ||
Show All 9 Lines |