Skip to content

Commit

Permalink
Merge pull request #483 from iptux-src/lidaobing/issue481
Browse files Browse the repository at this point in the history
#481: chatbox should has memory
  • Loading branch information
lidaobing authored Oct 8, 2021
2 parents 90d4130 + 200068d commit 96302de
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 87 deletions.
26 changes: 13 additions & 13 deletions src/iptux/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "iptux-utils/utils.h"
#include "iptux/AboutDialog.h"
#include "iptux/DataSettings.h"
#include "iptux/DialogPeer.h"
#include "iptux/IptuxResource.h"
#include "iptux/LogSystem.h"
#include "iptux/MainWindow.h"
Expand All @@ -19,7 +20,6 @@
#include "iptux/UiHelper.h"
#include "iptux/UiProgramData.h"
#include "iptux/dialog.h"
#include "iptux/DialogPeer.h"

#if SYSTEM_DARWIN
#include "iptux/TerminalNotifierNotificationService.h"
Expand Down Expand Up @@ -89,7 +89,7 @@ Application::Application(shared_ptr<IptuxConfig> config)

Application::~Application() {
g_object_unref(app);
if(menuBuilder) {
if (menuBuilder) {
g_object_unref(menuBuilder);
}
transModelDelete(transModel);
Expand Down Expand Up @@ -240,11 +240,12 @@ void Application::onEvent(shared_ptr<const Event> _event) {
auto title = stringFormat(_("New Message from %s"),
event->getMsgPara().getPal()->getName().c_str());
auto summary = event->getMsgPara().getSummary();
auto action = stringFormat("app.open-chat::%s",
event->getMsgPara().getPal()->GetKey().GetIpv4String().c_str());
auto action = stringFormat(
"app.open-chat::%s",
event->getMsgPara().getPal()->GetKey().GetIpv4String().c_str());
notificationService->sendNotification(
G_APPLICATION(app), "iptux-new-message", title, summary,
action, G_NOTIFICATION_PRIORITY_NORMAL, nullptr);
G_APPLICATION(app), "iptux-new-message", title, summary, action,
G_NOTIFICATION_PRIORITY_NORMAL, nullptr);
}
if (type == EventType::NEW_SHARE_FILE_FROM_FRIEND) {
const NewShareFileFromFriendEvent* event =
Expand Down Expand Up @@ -342,23 +343,22 @@ void Application::updateItemToTransTree(const TransFileModel& para) {
}

void Application::onOpenChat(GSimpleAction*,
GVariant* value,
Application& self) {
GVariant* value,
Application& self) {
string ipv4 = g_variant_get_string(value, nullptr);
auto pal = self.cthrd->GetPal(ipv4);
if(!pal) {
if (!pal) {
return;
}
auto groupInfo = self.cthrd->GetPalRegularItem(pal.get());
if(!groupInfo) {
if (!groupInfo) {
return;
}
if (groupInfo->dialog) {
gtk_window_present(GTK_WINDOW(groupInfo->dialog));
if (groupInfo->getDialog()) {
gtk_window_present(GTK_WINDOW(groupInfo->getDialog()));
return;
}
DialogPeer::PeerDialogEntry(&self, groupInfo);
}


} // namespace iptux
10 changes: 7 additions & 3 deletions src/iptux/DialogBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void DialogBase::ClearSublayerGeneral() {
if (progdt->IsAutoCleanChatHistory()) {
ClearHistoryTextView();
}
grpinf->dialog = NULL;
grpinf->clearDialog();
g_datalist_clear(&widset);
g_datalist_clear(&mdlset);
g_datalist_clear(&dtset);
Expand Down Expand Up @@ -254,9 +254,8 @@ GtkWidget* DialogBase::CreateInputArea() {
GTK_SHADOW_ETCHED_IN);
gtk_box_pack_start(GTK_BOX(box), sw, TRUE, TRUE, 0);

widget = gtk_text_view_new();
widget = gtk_text_view_new_with_buffer(grpinf->getInputBuffer());
inputTextviewWidget = GTK_TEXT_VIEW(widget);
inputBuffer = gtk_text_view_get_buffer(inputTextviewWidget);
gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(widget), GTK_WRAP_WORD);
gtk_drag_dest_add_uri_targets(widget);
gtk_container_add(GTK_CONTAINER(sw), widget);
Expand Down Expand Up @@ -789,4 +788,9 @@ gboolean DialogBase::UpdateFileSendUI(DialogBase* dlggrp) {
gtk_progress_bar_set_text(GTK_PROGRESS_BAR(pbar), progresstip.c_str());
return TRUE;
}

GtkTextBuffer* DialogBase::getInputBuffer() {
return grpinf->getInputBuffer();
}

} // namespace iptux
4 changes: 2 additions & 2 deletions src/iptux/DialogBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class DialogBase : public SessionAbstract, public sigc::trackable {
DialogBase(Application* app, GroupInfo* grp);
virtual ~DialogBase();

virtual GtkWindow* getWindow() = 0;
void ClearHistoryTextView();

protected:
Expand All @@ -45,12 +46,12 @@ class DialogBase : public SessionAbstract, public sigc::trackable {
virtual GtkWidget* CreateHistoryArea();
virtual GtkWidget* CreateFileSendArea();
virtual GtkWidget* CreateFileSendTree(GtkTreeModel* model);
virtual GtkWindow* getWindow() = 0;
virtual GSList* GetSelPal() { return NULL; };

void MainWindowSignalSetup(GtkWindow* window);
GtkTreeModel* CreateFileSendModel();
GSList* PickEnclosure(FileAttr fileattr);
GtkTextBuffer* getInputBuffer();

bool SendEnclosureMsg();
virtual bool SendTextMsg() = 0;
Expand Down Expand Up @@ -89,7 +90,6 @@ class DialogBase : public SessionAbstract, public sigc::trackable {
GtkTreeView* fileSendTree = 0;
GtkTextView* inputTextviewWidget = 0;

GtkTextBuffer* inputBuffer = 0;
GtkListStore* fileSendModel = 0;

GData* widset; //窗体集
Expand Down
6 changes: 3 additions & 3 deletions src/iptux/DialogGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ GtkWindow* DialogGroup::CreateMainWindow() {
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
g_datalist_set_data(&widset, "window-widget", window);
widget_enable_dnd_uri(GTK_WIDGET(window));
grpinf->dialog = GTK_WIDGET(window);
grpinf->setDialogBase(this);

MainWindowSignalSetup(GTK_WINDOW(window));

Expand Down Expand Up @@ -590,8 +590,8 @@ void DialogGroup::MembertreeItemActivated(GtkWidget* treeview,
gtk_tree_model_get_iter(model, &iter, path);
gtk_tree_model_get(model, &iter, 3, &pal, -1);
if ((grpinf = self->app->getCoreThread()->GetPalRegularItem(pal))) {
if ((grpinf->dialog))
gtk_window_present(GTK_WINDOW(grpinf->dialog));
if ((grpinf->getDialog()))
gtk_window_present(GTK_WINDOW(grpinf->getDialog()));
else
DialogPeer::PeerDialogEntry(self->app, grpinf);
}
Expand Down
20 changes: 9 additions & 11 deletions src/iptux/DialogPeer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,10 @@ DialogPeer::DialogPeer(Application* app, GroupInfo* grp)
* 类析构函数.
*/
DialogPeer::~DialogPeer() {
g_signal_handler_disconnect(G_OBJECT(grpinf->getInputBuffer()), sigId);
/* 非常重要,必须在窗口析构之前把定时触发事件停止,不然会出现意想不到的情况 */
if (timerrcv > 0)
g_source_remove(timerrcv);
// grpinf->disconnect(sigId);
/*---------------------------------------------------------------*/
WriteUILayout();
}

Expand All @@ -71,7 +70,7 @@ DialogPeer::~DialogPeer() {
* @param grpinf 好友群组信息
*/
void DialogPeer::PeerDialogEntry(Application* app, GroupInfo* grpinf) {
if (grpinf->dialog)
if (grpinf->getDialog())
return;

DialogPeer* dlgpr;
Expand All @@ -82,7 +81,7 @@ void DialogPeer::PeerDialogEntry(Application* app, GroupInfo* grpinf) {
void DialogPeer::init() {
auto dlgpr = this;
auto window = GTK_WIDGET(dlgpr->CreateMainWindow());
grpinf->dialog = window;
grpinf->setDialogBase(this);
gtk_container_add(GTK_CONTAINER(window), dlgpr->CreateAllArea());
gtk_widget_show_all(window);
gtk_widget_grab_focus(GTK_WIDGET(inputTextviewWidget));
Expand All @@ -103,8 +102,8 @@ void DialogPeer::init() {
G_N_ELEMENTS(win_entries), this);
g_action_map_disable_actions(G_ACTION_MAP(window), "refuse", nullptr);

g_signal_connect(G_OBJECT(inputBuffer), "changed",
G_CALLBACK(onInputBufferChanged), this);
sigId = g_signal_connect(G_OBJECT(getInputBuffer()), "changed",
G_CALLBACK(onInputBufferChanged), this);
g_signal_connect_swapped(G_OBJECT(fileSendModel), "row-deleted",
G_CALLBACK(onSendFileModelChanged), this);
g_signal_connect_swapped(G_OBJECT(fileSendModel), "row-inserted",
Expand Down Expand Up @@ -227,7 +226,6 @@ GtkWindow* DialogPeer::CreateMainWindow() {
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
widget_enable_dnd_uri(GTK_WIDGET(window));
g_datalist_set_data(&widset, "window-widget", window);
grpinf->dialog = GTK_WIDGET(window);
g_object_set_data(G_OBJECT(window), "dialog", this);

MainWindowSignalSetup(GTK_WINDOW(window));
Expand Down Expand Up @@ -392,7 +390,7 @@ bool DialogPeer::SendTextMsg() {
std::vector<ChipData> dtlist;

gtk_widget_grab_focus(GTK_WIDGET(inputTextviewWidget)); //为下一次任务做准备
buffer = inputBuffer;
buffer = getInputBuffer();
gtk_text_buffer_get_bounds(buffer, &start, &end);
if (gtk_text_iter_equal(&start, &end))
return false;
Expand Down Expand Up @@ -970,8 +968,8 @@ void DialogPeer::onAcceptButtonClicked(DialogPeer* self) {

auto g_progdt = self->app->getCoreThread()->getUiProgramData();

const gchar* filepath =
pop_save_path(GTK_WIDGET(self->grpinf->dialog), g_progdt->path.c_str());
const gchar* filepath = pop_save_path(GTK_WIDGET(self->grpinf->getDialog()),
g_progdt->path.c_str());
if (filepath == nullptr) {
return;
}
Expand Down Expand Up @@ -1103,7 +1101,7 @@ void DialogPeer::onGroupInfoUpdated(GroupInfo* groupInfo) {

void DialogPeer::refreshSendAction() {
bool can_send = false;
if (gtk_text_buffer_get_char_count(inputBuffer) > 0) {
if (gtk_text_buffer_get_char_count(getInputBuffer()) > 0) {
can_send = true;
} else {
GtkTreeIter iter;
Expand Down
37 changes: 19 additions & 18 deletions src/iptux/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,8 @@ GtkWidget* MainWindow::CreateMainWindow() {

g_signal_connect(window, "configure-event", G_CALLBACK(MWinConfigureEvent),
this);
g_signal_connect(window, "delete-event", G_CALLBACK(gtk_window_iconify_on_delete), nullptr);
g_signal_connect(window, "delete-event",
G_CALLBACK(gtk_window_iconify_on_delete), nullptr);
return window;
}

Expand Down Expand Up @@ -1179,8 +1180,8 @@ void MainWindow::onPaltreeItemActivated(GtkWidget* treeview,
gtk_tree_model_get_iter(model, &iter, path);
gtk_tree_model_get(model, &iter, 6, &grpinf, -1);
/* 检查是否需要新建对话框 */
if (grpinf->dialog) {
gtk_window_present(GTK_WINDOW(grpinf->dialog));
if (grpinf->getDialog()) {
gtk_window_present(GTK_WINDOW(grpinf->getDialog()));
return;
}

Expand Down Expand Up @@ -1321,7 +1322,7 @@ void MainWindow::PaltreeDragDataReceived(GtkWidget* treeview,
gtk_tree_model_get(model, &iter, 6, &grpinf, -1);

/* 如果好友群组对话框尚未创建,则先创建对话框 */
if (!(grpinf->dialog)) {
if (!(grpinf->getDialog())) {
switch (grpinf->getType()) {
case GROUP_BELONG_TYPE_REGULAR:
DialogPeer::PeerDialogEntry(self->app, grpinf);
Expand All @@ -1334,9 +1335,9 @@ void MainWindow::PaltreeDragDataReceived(GtkWidget* treeview,
break;
}
} else
gtk_window_present(GTK_WINDOW(grpinf->dialog));
gtk_window_present(GTK_WINDOW(grpinf->getDialog()));
/* 获取会话对象,并将数据添加到会话对象 */
session = (SessionAbstract*)g_object_get_data(G_OBJECT(grpinf->dialog),
session = (SessionAbstract*)g_object_get_data(G_OBJECT(grpinf->getDialog()),
"session-class");
list = selection_data_get_path(data); //获取所有文件
session->AttachEnclosure(list);
Expand Down Expand Up @@ -1387,8 +1388,8 @@ void MainWindow::onPalChangeInfo(void*, void*, MainWindow& self) {

void MainWindow::onPalSendMessage(void*, void*, MainWindow& self) {
GroupInfo* groupInfo = CHECK_NOTNULL(self.currentGroupInfo);
if (groupInfo->dialog) {
gtk_window_present(GTK_WINDOW(groupInfo->dialog));
if (groupInfo->getDialog()) {
gtk_window_present(GTK_WINDOW(groupInfo->getDialog()));
return;
}
switch (groupInfo->getType()) {
Expand Down Expand Up @@ -1517,10 +1518,10 @@ void MainWindow::PallistItemActivated(GtkWidget* treeview,
gtk_tree_model_get_iter(model, &iter, path);
gtk_tree_model_get(model, &iter, 6, &pal, -1);
if ((grpinf = self->coreThread.GetPalRegularItem(pal))) {
if (!(grpinf->dialog))
if (!(grpinf->getDialog()))
DialogPeer::PeerDialogEntry(self->app, grpinf);
else
gtk_window_present(GTK_WINDOW(grpinf->dialog));
gtk_window_present(GTK_WINDOW(grpinf->getDialog()));
}
}

Expand Down Expand Up @@ -1568,12 +1569,12 @@ void MainWindow::PallistDragDataReceived(GtkWidget* treeview,
return;

/* 如果好友群组对话框尚未创建,则先创建对话框 */
if (!(grpinf->dialog))
if (!(grpinf->getDialog()))
DialogPeer::PeerDialogEntry(self->app, grpinf);
else
gtk_window_present(GTK_WINDOW(grpinf->dialog));
gtk_window_present(GTK_WINDOW(grpinf->getDialog()));
/* 获取会话对象,并将数据添加到会话对象 */
session = (SessionAbstract*)g_object_get_data(G_OBJECT(grpinf->dialog),
session = (SessionAbstract*)g_object_get_data(G_OBJECT(grpinf->getDialog()),
"session-class");
list = selection_data_get_path(data); //获取所有文件
session->AttachEnclosure(list);
Expand Down Expand Up @@ -1661,10 +1662,10 @@ void MainWindow::processEventInMainThread(shared_ptr<const Event> _event) {
case GROUP_BELONG_TYPE_REGULAR:
grpinf = coreThread.GetPalRegularItem(para.getPal().get());
if (coreThread.getProgramData()->IsAutoOpenCharDialog()) {
if (!(grpinf->dialog)) {
if (!(grpinf->getDialog())) {
DialogPeer::PeerDialogEntry(this->app, grpinf);
} else {
gtk_window_present(GTK_WINDOW(grpinf->dialog));
gtk_window_present(GTK_WINDOW(grpinf->getDialog()));
}
}
break;
Expand All @@ -1686,9 +1687,9 @@ void MainWindow::processEventInMainThread(shared_ptr<const Event> _event) {
/* 群组不存在是编程上的错误,请发送Bug报告 */
if (grpinf) {
grpinf->addMsgPara(para);
if (grpinf->dialog) {
session = (SessionAbstract*)g_object_get_data(G_OBJECT(grpinf->dialog),
"session-class");
if (grpinf->getDialog()) {
session = (SessionAbstract*)g_object_get_data(
G_OBJECT(grpinf->getDialog()), "session-class");
session->OnNewMessageComing();
}
}
Expand Down
Loading

0 comments on commit 96302de

Please sign in to comment.