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