Annotation of truecrypt/main/forms/deviceselectiondialog.cpp, revision 1.1

1.1     ! root        1: /*
        !             2:  Copyright (c) 2008 TrueCrypt Foundation. All rights reserved.
        !             3: 
        !             4:  Governed by the TrueCrypt License 2.4 the full text of which is contained
        !             5:  in the file License.txt included in TrueCrypt binary and source code
        !             6:  distribution packages.
        !             7: */
        !             8: 
        !             9: #include "System.h"
        !            10: #include "Main/GraphicUserInterface.h"
        !            11: #include "Main/Resources.h"
        !            12: #include "DeviceSelectionDialog.h"
        !            13: 
        !            14: namespace TrueCrypt
        !            15: {
        !            16:        DeviceSelectionDialog::DeviceSelectionDialog (wxWindow* parent)
        !            17:                : DeviceSelectionDialogBase (parent)
        !            18:        {
        !            19:                wxBusyCursor busy;
        !            20: 
        !            21:                list <int> colPermilles;
        !            22: 
        !            23:                DeviceListCtrl->InsertColumn (ColumnDevice, LangString["DEVICE"], wxLIST_FORMAT_LEFT, 1);
        !            24:                colPermilles.push_back (447);
        !            25: #ifdef TC_WINDOWS
        !            26:                DeviceListCtrl->InsertColumn (ColumnDrive, LangString["DRIVE"], wxLIST_FORMAT_LEFT, 1);
        !            27:                colPermilles.push_back (91);
        !            28: #endif
        !            29:                DeviceListCtrl->InsertColumn (ColumnSize, LangString["SIZE"], wxLIST_FORMAT_RIGHT, 1);
        !            30:                colPermilles.push_back (153);
        !            31: #ifdef TC_WINDOWS
        !            32:                DeviceListCtrl->InsertColumn (ColumnName, LangString["VOLUME_LABEL"], wxLIST_FORMAT_LEFT, 1);
        !            33:                colPermilles.push_back (307);
        !            34: #else
        !            35:                DeviceListCtrl->InsertColumn (ColumnMountPoint, LangString["MOUNT_POINT"], wxLIST_FORMAT_LEFT, 1);
        !            36:                colPermilles.push_back (396);
        !            37: #endif
        !            38:  
        !            39:                wxImageList *imageList = new wxImageList (16, 12, true);
        !            40:                imageList->Add (Resources::GetDriveIconBitmap(), Resources::GetDriveIconMaskBitmap());
        !            41:                DeviceListCtrl->AssignImageList (imageList, wxIMAGE_LIST_SMALL);
        !            42: 
        !            43:                DeviceList = Core->GetHostDevices();
        !            44: 
        !            45:                foreach_ref (HostDevice &device, DeviceList)
        !            46:                {
        !            47:                        if (device.Size == 0)
        !            48:                                continue;
        !            49: 
        !            50:                        vector <wstring> fields (DeviceListCtrl->GetColumnCount());
        !            51: 
        !            52:                        if (DeviceListCtrl->GetItemCount() > 0)
        !            53:                                Gui->AppendToListCtrl (DeviceListCtrl, fields);
        !            54: 
        !            55: #ifdef TC_WINDOWS
        !            56:                        fields[ColumnDevice] = StringFormatter (L"{0} {1}:", _("Harddisk"), device.SystemNumber);
        !            57:                        fields[ColumnDrive] = device.MountPoint;
        !            58:                        fields[ColumnName] = device.Name;
        !            59: #else
        !            60:                        fields[ColumnDevice] = wstring (device.Path) + L":";
        !            61:                        fields[ColumnMountPoint] = device.MountPoint;
        !            62: #endif
        !            63:                        fields[ColumnSize] = Gui->SizeToString (device.Size);
        !            64:                        Gui->AppendToListCtrl (DeviceListCtrl, fields, 0, &device); 
        !            65: 
        !            66:                        foreach_ref (HostDevice &partition, device.Partitions)
        !            67:                        {
        !            68:                                fields[ColumnDevice] = 
        !            69: #ifndef TC_WINDOWS
        !            70:                                        wstring (L"      ") + 
        !            71: #endif
        !            72:                                        wstring (partition.Path);
        !            73: 
        !            74: #ifdef TC_WINDOWS
        !            75:                                fields[ColumnDrive] = partition.MountPoint;
        !            76:                                fields[ColumnName] = partition.Name;
        !            77: #else
        !            78:                                fields[ColumnMountPoint] = partition.MountPoint;
        !            79: #endif
        !            80:                                fields[ColumnSize] = Gui->SizeToString (partition.Size);
        !            81:                                Gui->AppendToListCtrl (DeviceListCtrl, fields, -1, &partition);
        !            82:                        }
        !            83:                }
        !            84: 
        !            85:                Gui->SetListCtrlWidth (DeviceListCtrl, 73);
        !            86:                Gui->SetListCtrlHeight (DeviceListCtrl, 16);
        !            87:                Gui->SetListCtrlColumnWidths (DeviceListCtrl, colPermilles);
        !            88: 
        !            89:                Fit();
        !            90:                Layout();
        !            91:                Center();
        !            92: 
        !            93:                StdButtonsOK->Disable();
        !            94:                StdButtonsOK->SetDefault();
        !            95:        }
        !            96:        
        !            97:        void DeviceSelectionDialog::OnListItemActivated (wxListEvent& event)
        !            98:        {
        !            99:                if (StdButtonsOK->IsEnabled())
        !           100:                        EndModal (wxID_OK);
        !           101:        }
        !           102: 
        !           103:        void DeviceSelectionDialog::OnListItemDeselected (wxListEvent& event)
        !           104:        {
        !           105:                if (DeviceListCtrl->GetSelectedItemCount() == 0)
        !           106:                        StdButtonsOK->Disable();
        !           107:        }
        !           108: 
        !           109:        void DeviceSelectionDialog::OnListItemSelected (wxListEvent& event)
        !           110:        {
        !           111:                HostDevice *device = (HostDevice *) (event.GetItem().GetData());
        !           112:                if (device)
        !           113:                {
        !           114:                        SelectedDevice = *device;
        !           115:                        StdButtonsOK->Enable();
        !           116:                }
        !           117:                else
        !           118:                        StdButtonsOK->Disable();
        !           119:        }
        !           120: }

unix.superglobalmegacorp.com

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