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