Changeset View
Changeset View
Standalone View
Standalone View
src/widgets/ruqolacentralwidget.cpp
Show All 14 Lines | 1 | /* | |||
---|---|---|---|---|---|
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License | ||
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to | ||
17 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 17 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | 18 | Boston, MA 02110-1301, USA. | ||
19 | */ | 19 | */ | ||
20 | 20 | | |||
21 | #include "ruqolacentralwidget.h" | 21 | #include "ruqolacentralwidget.h" | ||
22 | #include "ruqolaloginwidget.h" | 22 | #include "ruqolaloginwidget.h" | ||
23 | #include "ruqolamainwidget.h" | | |||
24 | #include "ruqola.h" | 23 | #include "ruqola.h" | ||
25 | #include "rocketchataccount.h" | 24 | #include "rocketchataccount.h" | ||
25 | #include "channellist/channellistwidget.h" | ||||
26 | #include "room/roomwidget.h" | ||||
27 | #include "misc/accountsoverviewwidget.h" | ||||
28 | | ||||
26 | #include <QVBoxLayout> | 29 | #include <QVBoxLayout> | ||
27 | #include <QStackedWidget> | 30 | #include <QStackedWidget> | ||
31 | #include <QSplitter> | ||||
28 | #include <KMessageBox> | 32 | #include <KMessageBox> | ||
29 | #include <KLocalizedString> | 33 | #include <KLocalizedString> | ||
30 | 34 | | |||
31 | RuqolaCentralWidget::RuqolaCentralWidget(QWidget *parent) | 35 | RuqolaCentralWidget::RuqolaCentralWidget(QWidget *parent) | ||
32 | : QWidget(parent) | 36 | : QWidget(parent) | ||
33 | { | 37 | { | ||
34 | auto *mainLayout = new QHBoxLayout(this); | 38 | auto *mainLayout = new QHBoxLayout(this); | ||
35 | mainLayout->setObjectName(QStringLiteral("mainlayout")); | 39 | mainLayout->setObjectName(QStringLiteral("mainlayout")); | ||
36 | 40 | | |||
41 | auto hSplitter = new QSplitter(this); | ||||
mlaurent: I created a separate class for allowing to test it.
So if you move here you need to readd… | |||||
42 | mainLayout->addWidget(hSplitter); | ||||
43 | | ||||
44 | auto vSplitter = new QSplitter(this); | ||||
45 | vSplitter->setOrientation(Qt::Vertical); | ||||
46 | hSplitter->addWidget(vSplitter); | ||||
47 | | ||||
48 | vSplitter->addWidget(new AccountsOverviewWidget(this)); | ||||
dfaure: Laurent: it's used here. | |||||
Oh on top ? Could you create a screenshot please ? mlaurent: Oh on top ? Could you create a screenshot please ?
(I prefere on statusbar. why on top ?) | |||||
I want this to be an item view, not buttons, this is a "usable intermediate state" olivierjg: I want this to be an item view, not buttons, this is a "usable intermediate state" | |||||
49 | | ||||
50 | mChannelListWidget = new ChannelListWidget(this); | ||||
51 | vSplitter->addWidget(mChannelListWidget); | ||||
52 | vSplitter->setStretchFactor(1, 1); | ||||
53 | | ||||
37 | mStackedWidget = new QStackedWidget(this); | 54 | mStackedWidget = new QStackedWidget(this); | ||
38 | mStackedWidget->setObjectName(QStringLiteral("mStackedWidget")); | 55 | hSplitter->addWidget(mStackedWidget); | ||
39 | mainLayout->addWidget(mStackedWidget); | 56 | hSplitter->setStretchFactor(1, 1); | ||
40 | 57 | | |||
41 | mRuqolaMainWidget = new RuqolaMainWidget(this); | 58 | mRoomWidget = new RoomWidget(this); | ||
42 | mRuqolaMainWidget->setObjectName(QStringLiteral("mRuqolaMainWidget")); | 59 | mStackedWidget->addWidget(mRoomWidget); | ||
43 | mStackedWidget->addWidget(mRuqolaMainWidget); | | |||
44 | 60 | | |||
45 | mRuqolaLoginWidget = new RuqolaLoginWidget(this); | 61 | mRuqolaLoginWidget = new RuqolaLoginWidget(this); | ||
46 | mRuqolaLoginWidget->setObjectName(QStringLiteral("mRuqolaLoginWidget")); | 62 | mRuqolaLoginWidget->setObjectName(QStringLiteral("mRuqolaLoginWidget")); | ||
47 | mStackedWidget->addWidget(mRuqolaLoginWidget); | 63 | mStackedWidget->addWidget(mRuqolaLoginWidget); | ||
48 | 64 | | |||
65 | connect(mChannelListWidget, &ChannelListWidget::channelSelected, this, [this](const QModelIndex &index) { | ||||
66 | Q_EMIT mRoomWidget->channelSelected(index); | ||||
67 | Q_EMIT channelSelected(); | ||||
68 | }); | ||||
69 | | ||||
49 | mStackedWidget->setCurrentWidget(mRuqolaLoginWidget); | 70 | mStackedWidget->setCurrentWidget(mRuqolaLoginWidget); | ||
50 | connect(mRuqolaMainWidget, &RuqolaMainWidget::channelSelected, this, &RuqolaCentralWidget::channelSelected); | | |||
51 | } | 71 | } | ||
52 | 72 | | |||
53 | RuqolaCentralWidget::~RuqolaCentralWidget() | 73 | RuqolaCentralWidget::~RuqolaCentralWidget() | ||
54 | { | 74 | { | ||
55 | } | 75 | } | ||
56 | 76 | | |||
57 | void RuqolaCentralWidget::slotJobFailedInfo(const QString &messageError) | 77 | void RuqolaCentralWidget::slotJobFailedInfo(const QString &messageError) | ||
58 | { | 78 | { | ||
59 | //TODO fix i18n | 79 | //TODO fix i18n | ||
60 | KMessageBox::error(this, messageError, i18n("Job Failed")); | 80 | KMessageBox::error(this, messageError, i18n("Job Failed")); | ||
61 | } | 81 | } | ||
62 | 82 | | |||
63 | void RuqolaCentralWidget::slotSocketError(QAbstractSocket::SocketError error, const QString &errorString) | 83 | void RuqolaCentralWidget::slotSocketError(QAbstractSocket::SocketError error, const QString &errorString) | ||
64 | { | 84 | { | ||
65 | Q_UNUSED(error); | 85 | Q_UNUSED(error); | ||
66 | // ## let's hope this happens while the login widget is visible, but that's quite likely | 86 | // ## let's hope this happens while the login widget is visible, but that's quite likely | ||
67 | // Testcase: try to connect to a server that doesn't exist | 87 | // Testcase: try to connect to a server that doesn't exist | ||
68 | mRuqolaLoginWidget->showError(errorString); | 88 | mRuqolaLoginWidget->showError(errorString); | ||
69 | } | 89 | } | ||
70 | 90 | | |||
71 | RoomWrapper *RuqolaCentralWidget::roomWrapper() const | 91 | RoomWrapper *RuqolaCentralWidget::roomWrapper() const | ||
72 | { | 92 | { | ||
73 | return mRuqolaMainWidget->roomWrapper(); | 93 | return mRoomWidget->roomWrapper(); | ||
74 | } | 94 | } | ||
75 | 95 | | |||
76 | QString RuqolaCentralWidget::roomId() const | 96 | QString RuqolaCentralWidget::roomId() const | ||
77 | { | 97 | { | ||
78 | return mRuqolaMainWidget->roomId(); | 98 | return mRoomWidget->roomId(); | ||
79 | } | 99 | } | ||
80 | 100 | | |||
81 | QString RuqolaCentralWidget::roomType() const | 101 | QString RuqolaCentralWidget::roomType() const | ||
82 | { | 102 | { | ||
83 | return mRuqolaMainWidget->roomType(); | 103 | return mRoomWidget->roomType(); | ||
84 | } | 104 | } | ||
85 | 105 | | |||
86 | void RuqolaCentralWidget::setCurrentRocketChatAccount(RocketChatAccount *account) | 106 | void RuqolaCentralWidget::setCurrentRocketChatAccount(RocketChatAccount *account) | ||
87 | { | 107 | { | ||
88 | 108 | | |||
89 | if (mCurrentRocketChatAccount) { | 109 | if (mCurrentRocketChatAccount) { | ||
90 | disconnect(mCurrentRocketChatAccount, nullptr, this, nullptr); | 110 | disconnect(mCurrentRocketChatAccount, nullptr, this, nullptr); | ||
91 | } | 111 | } | ||
92 | mCurrentRocketChatAccount = account; | 112 | mCurrentRocketChatAccount = account; | ||
93 | connect(mCurrentRocketChatAccount, &RocketChatAccount::loginStatusChanged, this, &RuqolaCentralWidget::slotLoginStatusChanged); | 113 | connect(mCurrentRocketChatAccount, &RocketChatAccount::loginStatusChanged, this, &RuqolaCentralWidget::slotLoginStatusChanged); | ||
94 | connect(mCurrentRocketChatAccount, &RocketChatAccount::socketError, this, &RuqolaCentralWidget::slotSocketError); | 114 | connect(mCurrentRocketChatAccount, &RocketChatAccount::socketError, this, &RuqolaCentralWidget::slotSocketError); | ||
95 | connect(mCurrentRocketChatAccount, &RocketChatAccount::jobFailed, this, &RuqolaCentralWidget::slotJobFailedInfo); | 115 | connect(mCurrentRocketChatAccount, &RocketChatAccount::jobFailed, this, &RuqolaCentralWidget::slotJobFailedInfo); | ||
96 | mRuqolaMainWidget->setCurrentRocketChatAccount(account); | 116 | mChannelListWidget->setCurrentRocketChatAccount(account); | ||
117 | mRoomWidget->setCurrentRocketChatAccount(account); | ||||
97 | //Check if account is connected or not. | 118 | //Check if account is connected or not. | ||
98 | slotLoginStatusChanged(); | 119 | slotLoginStatusChanged(); | ||
99 | } | 120 | } | ||
100 | 121 | | |||
101 | void RuqolaCentralWidget::slotLoginStatusChanged() | 122 | void RuqolaCentralWidget::slotLoginStatusChanged() | ||
102 | { | 123 | { | ||
103 | const auto loginStatus = mCurrentRocketChatAccount->loginStatus(); | 124 | const auto loginStatus = mCurrentRocketChatAccount->loginStatus(); | ||
104 | mRuqolaLoginWidget->setLoginStatus(loginStatus); | 125 | mRuqolaLoginWidget->setLoginStatus(loginStatus); | ||
105 | if (loginStatus == DDPClient::LoggedIn) { | 126 | if (loginStatus == DDPClient::LoggedIn) { | ||
106 | mStackedWidget->setCurrentWidget(mRuqolaMainWidget); | 127 | mStackedWidget->setCurrentWidget(mRoomWidget); | ||
107 | } else { | 128 | } else { | ||
108 | mStackedWidget->setCurrentWidget(mRuqolaLoginWidget); | 129 | mStackedWidget->setCurrentWidget(mRuqolaLoginWidget); | ||
109 | mRuqolaLoginWidget->initialize(); | 130 | mRuqolaLoginWidget->initialize(); | ||
110 | } | 131 | } | ||
111 | } | 132 | } |
I created a separate class for allowing to test it.
So if you move here you need to readd autotest
Thanks