Skip to content

Commit 2f61381

Browse files
committed
add default build type for cmake, improve SioChatDemo UI
1 parent 4232941 commit 2f61381

File tree

5 files changed

+43
-12
lines changed

5 files changed

+43
-12
lines changed

CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ install(TARGETS sioclient
3030
endfunction()
3131

3232
MESSAGE(STATUS ${CMAKE_CURRENT_LIST_DIR})
33+
if(NOT CMAKE_BUILD_TYPE )
34+
MESSAGE(STATUS "not define build type, set to release" )
35+
set(CMAKE_BUILD_TYPE Release )
36+
endif()
3337

3438
set(BOOST_VER "1.55.0" CACHE STRING "boost version" )
3539
set(BOOST_PATH "__boost__" CACHE STRING "boost root path" )

examples/QT/SioChatDemo/SioChatDemo.pro

+4-4
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,17 @@ DEPENDPATH += $$PWD/../../../build/lib
3232

3333
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../build/lib/release/ -lsioclient
3434
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../build/lib/debug/ -lsioclient
35-
else:unix: LIBS += -L$$PWD/../../../build/lib/ -lsioclient
35+
else:unix: LIBS += -L$$PWD/../../../build/lib/release -lsioclient
3636

3737

3838
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../build/lib/release/ -lboost_random
3939
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../build/lib/debug/ -lboost_random
40-
else:unix: LIBS += -L$$PWD/../../../build/lib/ -lboost_random
40+
else:unix: LIBS += -L$$PWD/../../../build/lib/release -lboost_random
4141

4242
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../build/lib/release/ -lboost_system
4343
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../build/lib/debug/ -lboost_system
44-
else:unix: LIBS += -L$$PWD/../../../build/lib/ -lboost_system
44+
else:unix: LIBS += -L$$PWD/../../../build/lib/release -lboost_system
4545

4646
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../build/lib/release/ -lboost_date_time
4747
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../build/lib/debug/ -lboost_date_time
48-
else:unix: LIBS += -L$$PWD/../../../build/lib/ -lboost_date_time
48+
else:unix: LIBS += -L$$PWD/../../../build/lib/release -lboost_date_time

examples/QT/SioChatDemo/mainwindow.cpp

+27-4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ MainWindow::MainWindow(QWidget *parent) :
1919
QMainWindow(parent),
2020
ui(new Ui::MainWindow),
2121
_io(new client()),
22+
m_typingItem(NULL),
2223
m_dialog()
2324
{
2425
ui->setupUi(this);
@@ -39,6 +40,7 @@ MainWindow::MainWindow(QWidget *parent) :
3940
_io->set_fail_listener(std::bind(&MainWindow::OnFailed,this));
4041

4142
connect(this,SIGNAL(RequestAddListItem(QListWidgetItem*)),this,SLOT(AddListItem(QListWidgetItem*)));
43+
connect(this,SIGNAL(RequestRemoveListItem(QListWidgetItem*)),this,SLOT(RemoveListItem(QListWidgetItem*)));
4244
connect(this,SIGNAL(RequestToggleInputs(bool)),this,SLOT(ToggleInputs(bool)));
4345
}
4446

@@ -58,7 +60,7 @@ void MainWindow::SendBtnClicked()
5860
QByteArray bytes = text.toUtf8();
5961
std::string msg(bytes.data(),bytes.length());
6062
_io->socket()->emit("new message",msg);
61-
text.append(":You");
63+
text.append(" : You");
6264
QListWidgetItem *item = new QListWidgetItem(text);
6365
item->setTextAlignment(Qt::AlignRight);
6466
Q_EMIT RequestAddListItem(item);
@@ -126,6 +128,14 @@ void MainWindow::AddListItem(QListWidgetItem* item)
126128
this->findChild<QListWidget*>("listView")->addItem(item);
127129
}
128130

131+
void MainWindow::RemoveListItem(QListWidgetItem* item)
132+
{
133+
QListWidget* list = this->findChild<QListWidget*>("listView");
134+
int row = list->row(item);
135+
delete list->takeItem(row);
136+
}
137+
138+
129139
void MainWindow::OnNewMessage(std::string const& name,message::ptr const& data,bool hasAck,message::ptr &ack_resp)
130140
{
131141

@@ -134,7 +144,7 @@ void MainWindow::OnNewMessage(std::string const& name,message::ptr const& data,b
134144
std::string msg = data->get_map()["message"]->get_string();
135145
std::string username = data->get_map()["username"]->get_string();
136146
QString label = QString::fromUtf8(username.data(),username.length());
137-
label.append(':');
147+
label.append(" : ");
138148
label.append(QString::fromUtf8(msg.data(),msg.length()));
139149
QListWidgetItem *item= new QListWidgetItem(label);
140150
Q_EMIT RequestAddListItem(item);
@@ -200,12 +210,25 @@ void MainWindow::OnUserLeft(std::string const& name,message::ptr const& data,boo
200210

201211
void MainWindow::OnTyping(std::string const& name,message::ptr const& data,bool hasAck,message::ptr &ack_resp)
202212
{
203-
//Not implemented
213+
if(m_typingItem == NULL)
214+
{
215+
std::string name = data->get_map()["username"]->get_string();
216+
QString label = QString::fromUtf8(name.data(),name.length());
217+
label.append(" is typing...");
218+
QListWidgetItem *item = new QListWidgetItem(label);
219+
item->setTextColor(QColor(200,200,200,255));
220+
m_typingItem = item;
221+
Q_EMIT RequestAddListItem(item);
222+
}
204223
}
205224

206225
void MainWindow::OnStopTyping(std::string const& name,message::ptr const& data,bool hasAck,message::ptr &ack_resp)
207226
{
208-
//Not implemented
227+
if(m_typingItem != NULL)
228+
{
229+
Q_EMIT RequestRemoveListItem(m_typingItem);
230+
m_typingItem = NULL;
231+
}
209232
}
210233

211234
void MainWindow::OnLogin(std::string const& name,message::ptr const& data,bool hasAck,message::ptr &ack_resp)

examples/QT/SioChatDemo/mainwindow.h

+4
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ public Q_SLOTS:
3131

3232
Q_SIGNALS:
3333
void RequestAddListItem(QListWidgetItem *item);
34+
void RequestRemoveListItem(QListWidgetItem *item);
3435
void RequestToggleInputs(bool loginOrNot);
3536
private Q_SLOTS:
3637
void AddListItem(QListWidgetItem *item);
38+
void RemoveListItem(QListWidgetItem *item);
3739
void ToggleInputs(bool loginOrNot);
3840
void TypingStop();
3941
void NicknameAccept();
@@ -59,6 +61,8 @@ private Q_SLOTS:
5961
QString m_name;
6062

6163
std::unique_ptr<QTimer> m_timer;
64+
65+
QListWidgetItem *m_typingItem;
6266
};
6367

6468
#endif // MAINWINDOW_H

examples/QT/SioChatDemo/nicknamedialog.ui

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>405</width>
9+
<width>366</width>
1010
<height>170</height>
1111
</rect>
1212
</property>
@@ -16,7 +16,7 @@
1616
<widget class="QDialogButtonBox" name="buttonBox">
1717
<property name="geometry">
1818
<rect>
19-
<x>40</x>
19+
<x>16</x>
2020
<y>110</y>
2121
<width>341</width>
2222
<height>32</height>
@@ -32,7 +32,7 @@
3232
<widget class="QLineEdit" name="nicknameEdit">
3333
<property name="geometry">
3434
<rect>
35-
<x>36</x>
35+
<x>11</x>
3636
<y>60</y>
3737
<width>341</width>
3838
<height>20</height>
@@ -45,7 +45,7 @@
4545
<widget class="QLabel" name="label">
4646
<property name="geometry">
4747
<rect>
48-
<x>70</x>
48+
<x>44</x>
4949
<y>20</y>
5050
<width>271</width>
5151
<height>21</height>

0 commit comments

Comments
 (0)