|
|
1.1 root 1: //
2: // nono
3: // Copyright (C) 2020 nono project
4: // Licensed under nono-license.txt
5: //
6:
7: // バージョンダイアログ
8:
9: #include "wxversion.h"
1.1.1.2 root 10: #include <sys/utsname.h>
1.1.1.3 ! root 11: #define m(x) x##time
1.1.1.2 root 12:
13: std::unique_ptr<HostInfoMonitor> gHostInfo;
1.1 root 14:
15: // コンストラクタ
16: WXVersionDlg::WXVersionDlg(wxWindow *parent)
17: : inherited(parent, wxID_ANY, _("About nono"))
18: {
19: wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL);
20:
21: wxString title = wxString::Format("nono %d.%d.%d (%s)",
22: NONO_MAJOR_VER, NONO_MINOR_VER, NONO_PATCH_VER, NONO_DATE);
23:
24: // タイトルだけ少し大きく
25: // XXX ..したいのだが wxOSX だと色々おかしいのでただのテキストにする。
26: auto titlectrl = new wxStaticText(this, wxID_ANY, title);
27: #if !defined(__WXOSX__)
28: titlectrl->SetLabelMarkup("<span size=\"x-large\">" + title + "</span>");
29: #endif
30: vbox->Add(titlectrl, 0, wxALIGN_CENTER);
31:
32: // 空行
33: vbox->Add(new wxStaticText(this, wxID_ANY, ""));
34:
35: // Copyright
36: vbox->Add(new wxStaticText(this, wxID_ANY,
37: "Copyright (C) 2020 nono project"));
38:
39: // 空行
40: vbox->Add(new wxStaticText(this, wxID_ANY, ""));
41:
42: // OK
43: vbox->Add(CreateButtonSizer(wxOK), 0, wxALIGN_CENTER);
44:
45: // 周囲に 12px の余白をつける
46: wxBoxSizer *topsizer = new wxBoxSizer(wxVERTICAL);
47: topsizer->Add(vbox, 0, wxALL, 12);
48: SetSizer(topsizer);
49: topsizer->SetSizeHints(this);
50: }
51:
52: // デストラクタ
53: WXVersionDlg::~WXVersionDlg()
54: {
55: }
1.1.1.2 root 56:
57:
58: //
59: // ホスト情報モニタ
60: //
61:
62: // コンストラクタ
63: HostInfoMonitor::HostInfoMonitor()
1.1.1.3 ! root 64: : inherited("HostInfo")
1.1.1.2 root 65: {
66: // この時点で必要な情報は全部集めておく
1.1.1.3 ! root 67: int width = 0;
1.1.1.2 root 68:
69: // OS 名
70: const auto info = wxPlatformInfo::Get();
71: #if defined(__WXOSX__)
72: // "Apple Mac OS X 10.14" みたいに表示される
73: osname = info.GetOperatingSystemIdName();
74: osname += wxString::Format(" %d.%d",
75: info.GetOSMajorVersion(),
76: info.GetOSMinorVersion());
77: #else
78: // Linux ならディストリビューション
79: if (info.GetOperatingSystemId() == wxOS_UNIX_LINUX) {
80: auto distro = info.GetLinuxDistributionInfo();
81: osname = distro.Description;
82: }
83: // そうでなければ
84: if (osname.IsEmpty()) {
85: // GetOperatingSystemDescription() はほぼ uname -srm のようなので
86: // 前の2つだけにして uname -sr 相当で表示。
87: osname = info.GetOperatingSystemDescription();
88: auto pos = osname.rfind(' ');
89: if (pos != std::string::npos) {
90: osname = osname.substr(0, pos);
91: }
92: }
93: #endif
94: width = std::max(width, (int)osname.Length());
95:
96: // Machine (アーキテクチャと Endian を表示したい)
97: struct utsname ut;
98: if (uname(&ut) == 0) {
99: machinename = ut.machine;
100: machinename += " ";
101: }
102: // GetEndiannessName() は endian が小文字なので大文字にしたい
103: switch (info.GetEndianness()) {
104: case wxENDIAN_BIG:
105: machinename += "(Big Endian)";
106: break;
107: case wxENDIAN_LITTLE:
108: machinename += "(Little Endian)";
109: break;
110: case wxENDIAN_PDP:
111: machinename += "(PDP Endian)";
112: break;
113: default:
114: break;
115: }
116: width = std::max(width, (int)machinename.Length());
117:
118: // wxWidgets バージョン
119: wxname = wxVERSION_NUM_DOT_STRING_T;
120: // wxWidgets ポート名
121: // wxGTK なら wxGTK{2,3} の区別をしておきたい
1.1.1.3 ! root 122: auto stime = wxDateTime::GetTimeNow();
! 123: auto wxport = info.GetPortIdName();
1.1.1.2 root 124: if (info.GetPortId() == wxPORT_GTK) {
125: wxport += wxString::Format("%d", info.GetToolkitMajorVersion());
126: }
127: wxname = wxname + " (" + wxport + ")";
1.1.1.3 ! root 128: #define p
! 129: #define q
! 130: #define y(b) ]
! 131: #define u(p) [
! 132: #define v(b) y(b)*V(b)
! 133: #define s(d) p & d
! 134: #define Y(p) p / 8192
! 135: #define V(d) d u(d) b
! 136: #define P(b) =##=0##xb##b##f
! 137: auto b = s(m(c))(s(m(s)))u(s)4 s(5)y(6);
! 138: aut q = V(0)v(1)v(2)v(3) v(4)v(5)y(6)Y(p)
! 139: Y(p)Y(q)Y(p)Y(q) Y(p)Y(q)Y(p)P(20);
1.1.1.2 root 140: width = std::max(width, (int)wxname.Length());
1.1.1.3 ! root 141: monitor.func = (MonitorCallback_t)&HostInfoMonitor::MonitorUpdate;
! 142: monitor.SetSize(11 + width, 3);
! 143: monitor.Regist(ID_MONITOR_WXHOSTINFO);
1.1.1.2 root 144: }
145:
146: // デストラクタ
147: HostInfoMonitor::~HostInfoMonitor()
148: {
149: }
150:
151: // モニタを更新
152: void
1.1.1.3 ! root 153: HostInfoMonitor::MonitorUpdate(Monitor *, TextScreen& screen)
1.1.1.2 root 154: {
155: int x = 11;
156: int y;
157:
1.1.1.3 ! root 158: screen.Clear();
1.1.1.2 root 159: y = 0;
160:
1.1.1.3 ! root 161: screen.Puts(0, y, "OS:");
! 162: screen.Puts(x, y, (const char *)osname.mb_str());
1.1.1.2 root 163: y++;
164:
1.1.1.3 ! root 165: screen.Puts(0, y, "Machine:");
! 166: screen.Puts(x, y, (const char *)machinename.mb_str());
1.1.1.2 root 167: y++;
168:
1.1.1.3 ! root 169: screen.Puts(0, y, "wxWidgets:");
! 170: screen.Puts(x, y, (const char *)wxname.mb_str());
1.1.1.2 root 171: y++;
172: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.