Skip to content

Commit

Permalink
主窗口和任务栏窗口中新增今日总流量的显示 #1174
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongyang219 committed Jan 18, 2025
1 parent d2e88e5 commit df2290d
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 2 deletions.
3 changes: 3 additions & 0 deletions TrafficMonitor/DisplayTextSettingDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ void CDisplayTextSettingDlg::OnBnClickedRestoreDefaultButton()
case TDI_TOTAL_SPEED:
default_text = _T("↑↓: ");
break;
case TDI_TODAY_TRAFFIC:
default_text = CCommon::LoadText(IDS_TRAFFIC_USED, _T(": "));
break;
case TDI_CPU:
default_text = _T("CPU: ");
break;
Expand Down
11 changes: 11 additions & 0 deletions TrafficMonitor/SkinFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,9 @@ void CSkinFile::DrawPreview(CDC* pDC, CRect rect)
case TDI_TOTAL_SPEED:
draw_str.value = _T("90 KB/s");
break;
case TDI_TODAY_TRAFFIC:
draw_str.value = _T("100 MB");
break;
case TDI_CPU:
draw_str.value = _T("50 %");
break;
Expand Down Expand Up @@ -605,6 +608,7 @@ void CSkinFile::DrawItemsInfo(IDrawCommon& drawer, Layout& layout, CFont& font)
map_str[TDI_GPU_TEMP].label = theApp.m_main_wnd_data.disp_str.Get(TDI_GPU_TEMP).c_str();
map_str[TDI_HDD_TEMP].label = theApp.m_main_wnd_data.disp_str.Get(TDI_HDD_TEMP).c_str();
map_str[TDI_MAIN_BOARD_TEMP].label = theApp.m_main_wnd_data.disp_str.Get(TDI_MAIN_BOARD_TEMP).c_str();
map_str[TDI_TODAY_TRAFFIC].label = theApp.m_main_wnd_data.disp_str.Get(TDI_TODAY_TRAFFIC).c_str();
}

//上传/下载
Expand Down Expand Up @@ -651,6 +655,10 @@ void CSkinFile::DrawItemsInfo(IDrawCommon& drawer, Layout& layout, CFont& font)
getTemperatureStr(TDI_HDD_TEMP, theApp.m_hdd_temperature);
getTemperatureStr(TDI_MAIN_BOARD_TEMP, theApp.m_main_board_temperature);

//总流量
CString str_traffic = CCommon::KBytesToString((theApp.m_today_up_traffic + theApp.m_today_down_traffic) / 1024u);
map_str[TDI_TODAY_TRAFFIC].value = str_traffic.GetString();

//获取文本颜色
std::map<CommonDisplayItem, COLORREF> text_colors{};
if (theApp.m_main_wnd_data.specify_each_item_color)
Expand Down Expand Up @@ -742,6 +750,9 @@ string CSkinFile::GetDisplayItemXmlNodeName(DisplayItem display_item)
case TDI_TOTAL_SPEED:
return "total_speed";
break;
case TDI_TODAY_TRAFFIC:
return "today_traffic";
break;
case TDI_CPU:
return "cpu";
break;
Expand Down
7 changes: 7 additions & 0 deletions TrafficMonitor/TaskBarDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,10 @@ void CTaskBarDlg::DrawDisplayItem(IDrawCommon& drawer, DisplayItem type, CRect r
else if (type == TDI_CPU_FREQ) {
str_value = CCommon::FreqToString(theApp.m_cpu_freq, theApp.m_taskbar_data);
}
else if (type == TDI_TODAY_TRAFFIC)
{
str_value = CCommon::KBytesToString((theApp.m_today_up_traffic + theApp.m_today_down_traffic) / 1024u);
}

drawer.DrawWindowText(rect_value, str_value, text_color, value_alignment);
}
Expand Down Expand Up @@ -1102,6 +1106,9 @@ void CTaskBarDlg::CalculateWindowSize()
item_widths[TDI_HDD_TEMP].value_width = value_width;
item_widths[TDI_MAIN_BOARD_TEMP].value_width = value_width;

//今日已使用流量宽度
item_widths[TDI_TODAY_TRAFFIC].value_width = m_pDC->GetTextExtent(_T("999.99 MB")).cx;

//计算插件项目的宽度
for (const auto& plugin : theApp.m_plugins.GetPluginItems())
{
Expand Down
5 changes: 5 additions & 0 deletions TrafficMonitor/TaskbarItemOrderHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ CString CommonDisplayItem::GetItemName() const
case TDI_MEMORY:
item_name = CCommon::LoadText(IDS_MEMORY_USAGE);
break;
case TDI_TODAY_TRAFFIC:
item_name = CCommon::LoadText(IDS_TRAFFIC_USED);
break;
#ifndef WITHOUT_TEMPERATURE
case TDI_GPU_USAGE:
item_name = CCommon::LoadText(IDS_GPU_USAGE);
Expand Down Expand Up @@ -208,6 +211,8 @@ CString CTaskbarItemOrderHelper::GetItemDisplayName(CommonDisplayItem item)
return CCommon::LoadText(IDS_HDD_USAGE);
case TDI_CPU_FREQ:
return CCommon::LoadText(IDS_CPU_FREQ);
case TDI_TODAY_TRAFFIC:
return CCommon::LoadText(IDS_TRAFFIC_USED);
default:
break;
}
Expand Down
5 changes: 3 additions & 2 deletions TrafficMonitor/TaskbarItemOrderHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ enum DisplayItem
TDI_MAIN_BOARD_TEMP = 1 << 8,
TDI_HDD_USAGE = 1 << 9,
TDI_TOTAL_SPEED = 1 << 10,
TDI_CPU_FREQ = 1 << 11
TDI_CPU_FREQ = 1 << 11,
TDI_TODAY_TRAFFIC = 1 << 12
};

//显示的项目
Expand All @@ -42,7 +43,7 @@ const std::set<DisplayItem> AllDisplayItems
#ifndef WITHOUT_TEMPERATURE
, TDI_GPU_USAGE, TDI_CPU_TEMP, TDI_GPU_TEMP, TDI_HDD_TEMP, TDI_MAIN_BOARD_TEMP, TDI_HDD_USAGE,TDI_CPU_FREQ
#endif
, TDI_TOTAL_SPEED
, TDI_TOTAL_SPEED, TDI_TODAY_TRAFFIC
};


Expand Down
4 changes: 4 additions & 0 deletions TrafficMonitor/TrafficMonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ void CTrafficMonitorApp::LoadConfig()
m_main_wnd_data.disp_str.Get(TDI_HDD_TEMP) = ini.GetString(L"config", L"hdd_temp_string", CCommon::LoadText(IDS_HDD_DISP, _T(": $")));
m_main_wnd_data.disp_str.Get(TDI_MAIN_BOARD_TEMP) = ini.GetString(L"config", L"main_board_temp_string", CCommon::LoadText(IDS_MAINBOARD_DISP, _T(": $")));
m_main_wnd_data.disp_str.Get(TDI_HDD_USAGE) = ini.GetString(L"config", L"hdd_string", CCommon::LoadText(IDS_HDD_DISP, _T(": $")));
m_main_wnd_data.disp_str.Get(TDI_TODAY_TRAFFIC) = ini.GetString(L"config", L"today_traffic_string", CCommon::LoadText(IDS_TRAFFIC_USED, _T(": $")));

//载入插件项目的显示文本设置
ini.LoadPluginDisplayStr(true);
Expand Down Expand Up @@ -241,6 +242,7 @@ void CTrafficMonitorApp::LoadConfig()
m_taskbar_data.disp_str.Get(TDI_MAIN_BOARD_TEMP) = ini.GetString(L"task_bar", L"main_board_temp_string", CCommon::LoadText(IDS_MAINBOARD_DISP, _T(": ")));
m_taskbar_data.disp_str.Get(TDI_HDD_USAGE) = ini.GetString(L"task_bar", L"hdd_string", CCommon::LoadText(IDS_HDD_DISP, _T(": ")));
m_taskbar_data.disp_str.Get(TDI_CPU_FREQ) = ini.GetString(L"task_bar", L"cpu_freq_string", CCommon::LoadText(IDS_CPU_FREQ, _T(": $")));
m_taskbar_data.disp_str.Get(TDI_TODAY_TRAFFIC) = ini.GetString(L"task_bar", L"today_traffic_string", CCommon::LoadText(IDS_TRAFFIC_USED, _T(": $")));
ini.LoadPluginDisplayStr(false);

m_taskbar_data.tbar_wnd_on_left = ini.GetBool(_T("task_bar"), _T("task_bar_wnd_on_left"), false);
Expand Down Expand Up @@ -371,6 +373,7 @@ void CTrafficMonitorApp::SaveConfig()
ini.WriteString(_T("config"), _T("hdd_temp_string"), m_main_wnd_data.disp_str.Get(TDI_HDD_TEMP));
ini.WriteString(_T("config"), _T("main_board_temp_string"), m_main_wnd_data.disp_str.Get(TDI_MAIN_BOARD_TEMP));
ini.WriteString(_T("config"), _T("hdd_string"), m_main_wnd_data.disp_str.Get(TDI_HDD_USAGE));
ini.WriteString(_T("config"), _T("today_traffic_string"), m_main_wnd_data.disp_str.Get(TDI_TODAY_TRAFFIC));
ini.SavePluginDisplayStr(true);

ini.WriteBool(L"config", L"speed_short_mode", m_main_wnd_data.speed_short_mode);
Expand Down Expand Up @@ -423,6 +426,7 @@ void CTrafficMonitorApp::SaveConfig()
ini.WriteString(_T("task_bar"), _T("hdd_temp_string"), m_taskbar_data.disp_str.Get(TDI_HDD_TEMP));
ini.WriteString(_T("task_bar"), _T("main_board_temp_string"), m_taskbar_data.disp_str.Get(TDI_MAIN_BOARD_TEMP));
ini.WriteString(_T("task_bar"), _T("hdd_string"), m_taskbar_data.disp_str.Get(TDI_HDD_USAGE));
ini.WriteString(_T("task_bar"), _T("today_traffic_string"), m_taskbar_data.disp_str.Get(TDI_TODAY_TRAFFIC));
ini.SavePluginDisplayStr(false);

ini.WriteBool(L"task_bar", L"task_bar_wnd_on_left", m_taskbar_data.tbar_wnd_on_left);
Expand Down

0 comments on commit df2290d

Please sign in to comment.