"Fossies" - the Fresh Open Source Software Archive

Member "src/Main/Forms/DeviceSelectionDialog.cpp" (10 Oct 2018, 3703 Bytes) of package /windows/misc/VeraCrypt_1.23-Hotfix-2_Source.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "DeviceSelectionDialog.cpp" see the Fossies "Dox" file reference documentation.

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