Annotation of nono/wx/wxversion.cpp, revision 1.1.1.7

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.