Skip to content

Commit

Permalink
can open log from menu (#376)
Browse files Browse the repository at this point in the history
  • Loading branch information
lidaobing authored Mar 17, 2021
1 parent 9838464 commit 69ef2f7
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 17 deletions.
14 changes: 14 additions & 0 deletions src/iptux/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#include "iptux/UiHelper.h"
#include "iptux/UiProgramData.h"
#include "iptux/HelpDialog.h"
#include "iptux/UiCoreThread.h"
#include "iptux/LogSystem.h"

#if SYSTEM_DARWIN
#include "iptux/Darwin.h"
Expand Down Expand Up @@ -100,6 +102,8 @@ void Application::onStartup(Application& self) {
{ "help.report_bug", G_ACTION_CALLBACK(onReportBug), NULL, NULL, NULL, {0,0,0}},
{ "tools.transmission", G_ACTION_CALLBACK(onToolsTransmission), NULL, NULL, NULL, {0,0,0}},
{ "tools.shared_management", G_ACTION_CALLBACK(onToolsSharedManagement), NULL, NULL, NULL, {0,0,0}},
{ "tools.open_chat_log", G_ACTION_CALLBACK(onOpenChatLog), NULL, NULL, NULL, {0,0,0}},
{ "tools.open_system_log", G_ACTION_CALLBACK(onOpenSystemLog), NULL, NULL, NULL, {0,0,0}},
{ "trans_model.changed" },
{ "trans_model.clear", G_ACTION_CALLBACK(onTransModelClear)},
{ "about", G_ACTION_CALLBACK(onAbout)},
Expand Down Expand Up @@ -172,6 +176,16 @@ void Application::onToolsSharedManagement(void *, void *, Application &self) {
share_file_run(self.shareFile);
}

void Application::onOpenChatLog(void *, void *, Application &self) {
auto path = self.getCoreThread()->getLogSystem()->getChatLogPath();
iptux_open_url(path.c_str());
}

void Application::onOpenSystemLog(void *, void *, Application &self) {
auto path = self.getCoreThread()->getLogSystem()->getSystemLogPath();
iptux_open_url(path.c_str());
}

void Application::onTransModelClear(void *, void *, Application &self) {
GtkTreeIter iter;
int taskId;
Expand Down
2 changes: 2 additions & 0 deletions src/iptux/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class Application {
static void onStartup (Application& self);
static void onToolsSharedManagement (void *, void *, Application& self);
static void onToolsTransmission (void *, void *, Application& self);
static void onOpenChatLog (void *, void *, Application& self);
static void onOpenSystemLog (void *, void *, Application& self);
static void onTransModelClear (void *, void *, Application& self);
};

Expand Down
21 changes: 13 additions & 8 deletions src/iptux/LogSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,8 @@ LogSystem::~LogSystem() {
}

void LogSystem::InitSublayer() {
const gchar *env;
char path[MAX_PATHLEN];

env = g_get_user_config_dir();
snprintf(path, MAX_PATHLEN, "%s" LOG_PATH "/communicate.log", env);
fdc = open(path, O_WRONLY | O_CREAT | O_APPEND, 0644);
snprintf(path, MAX_PATHLEN, "%s" LOG_PATH "/system.log", env);
fds = open(path, O_WRONLY | O_CREAT | O_APPEND, 0644);
fdc = open(getChatLogPath().c_str(), O_WRONLY | O_CREAT | O_APPEND, 0644);
fds = open(getSystemLogPath().c_str(), O_WRONLY | O_CREAT | O_APPEND, 0644);
}

void LogSystem::CommunicateLog(MsgPara *msgpara, const char *fmt, va_list ap) {
Expand Down Expand Up @@ -97,4 +91,15 @@ void LogSystem::SystemLog(const char *fmt, va_list ap) {
g_free(log);
}

string LogSystem::getChatLogPath() const {
auto env = g_get_user_config_dir();
return stringFormat("%s" LOG_PATH "/communicate.log", env);
}

string LogSystem::getSystemLogPath() const {
auto env = g_get_user_config_dir();
return stringFormat("%s" LOG_PATH "/system.log", env);
}


} // namespace iptux
3 changes: 3 additions & 0 deletions src/iptux/LogSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ class LogSystem {
void CommunicateLog(MsgPara *msgpara, const char *fmt, va_list args);
void SystemLog(const char *fmt, va_list args);

std::string getChatLogPath() const;
std::string getSystemLogPath() const;

private:
std::shared_ptr<const ProgramData> programData;
int fdc, fds;
Expand Down
2 changes: 2 additions & 0 deletions src/iptux/UiCoreThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ class UiCoreThread: public CoreThread {
void CommunicateLog(MsgPara *msgpara, const char *fmt, ...) const G_GNUC_PRINTF(3, 4);
void SystemLog(const char *fmt, ...) const G_GNUC_PRINTF(2, 3);

LogSystem* getLogSystem() { return logSystem; }

private:
void InitSublayer();
void ClearSublayer() override ;
Expand Down
31 changes: 22 additions & 9 deletions src/iptux/resources/gtk/menus.ui
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,8 @@
</item>
</submenu>
<submenu>
<attribute name='label' translatable='yes'>_Tools</attribute>
<attribute name='label' translatable='yes'>_View</attribute>
<section>
<item>
<attribute name="label" translatable="yes">_Transmission</attribute>
<attribute name="action">app.tools.transmission</attribute>
</item>
<item>
<attribute name='label' translatable='yes'>_Shared Management</attribute>
<attribute name='action'>app.tools.shared_management</attribute>
</item>
<submenu>
<attribute name='label' translatable='yes'>Sort</attribute>
<section>
Expand Down Expand Up @@ -104,6 +96,27 @@
</item>
</section>
</submenu>
<submenu>
<attribute name='label' translatable='yes'>_Window</attribute>
<section>
<item>
<attribute name="label" translatable="yes">_Transmission</attribute>
<attribute name="action">app.tools.transmission</attribute>
</item>
<item>
<attribute name='label' translatable='yes'>_Shared Management</attribute>
<attribute name='action'>app.tools.shared_management</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_Chat Log</attribute>
<attribute name="action">app.tools.open_chat_log</attribute>
</item>
<item>
<attribute name='label' translatable='yes'>_System Log</attribute>
<attribute name='action'>app.tools.open_system_log</attribute>
</item>
</section>
</submenu>
<submenu>
<attribute name='label' translatable='yes'>_Help</attribute>
<section>
Expand Down

0 comments on commit 69ef2f7

Please sign in to comment.