"Fossies" - the Fresh Open Source Software Archive

Member "src/Main/Forms/KeyfilesPanel.cpp" (10 Oct 2018, 4279 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 "KeyfilesPanel.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 "KeyfilesPanel.h"
   16 #include "SecurityTokenKeyfilesDialog.h"
   17 
   18 namespace VeraCrypt
   19 {
   20     KeyfilesPanel::KeyfilesPanel (wxWindow* parent, shared_ptr <KeyfileList> keyfiles)
   21         : KeyfilesPanelBase (parent)
   22     {
   23         KeyfilesListCtrl->InsertColumn (0, LangString["KEYFILE"], wxLIST_FORMAT_LEFT, 1);
   24         Gui->SetListCtrlHeight (KeyfilesListCtrl, 10);
   25 
   26         Layout();
   27         Fit();
   28 
   29         if (keyfiles)
   30         {
   31             foreach_ref (const Keyfile &k, *keyfiles)
   32             {
   33                 vector <wstring> fields;
   34                 fields.push_back (FilesystemPath (k));
   35                 Gui->AppendToListCtrl (KeyfilesListCtrl, fields);
   36             }
   37         }
   38 
   39         class FileDropTarget : public wxFileDropTarget
   40         {
   41         public:
   42             FileDropTarget (KeyfilesPanel *panel) : Panel (panel) { }
   43 
   44             wxDragResult OnDragOver (wxCoord x, wxCoord y, wxDragResult def)
   45             {
   46                 return wxDragLink;
   47             }
   48 
   49             bool OnDropFiles (wxCoord x, wxCoord y, const wxArrayString &filenames)
   50             {
   51                 foreach (const wxString &f, filenames)
   52                     Panel->AddKeyfile (make_shared <Keyfile> (wstring (f)));
   53                 return true;
   54             }
   55 
   56         protected:
   57             KeyfilesPanel *Panel;
   58         };
   59 
   60         SetDropTarget (new FileDropTarget (this));
   61         KeyfilesListCtrl->SetDropTarget (new FileDropTarget (this));
   62 #ifdef TC_MACOSX
   63         foreach (wxWindow *c, GetChildren())
   64             c->SetDropTarget (new FileDropTarget (this));
   65 #endif
   66 
   67         UpdateButtons();
   68     }
   69 
   70     void KeyfilesPanel::AddKeyfile (shared_ptr <Keyfile> keyfile)
   71     {
   72         vector <wstring> fields;
   73         fields.push_back (FilesystemPath (*keyfile));
   74         Gui->AppendToListCtrl (KeyfilesListCtrl, fields);
   75         UpdateButtons();
   76     }
   77 
   78     shared_ptr <KeyfileList> KeyfilesPanel::GetKeyfiles () const
   79     {
   80         make_shared_auto (KeyfileList, keyfiles);
   81 
   82         for (long i = 0; i < KeyfilesListCtrl->GetItemCount(); i++)
   83             keyfiles->push_back (make_shared <Keyfile> (wstring (KeyfilesListCtrl->GetItemText (i))));
   84 
   85         return keyfiles;
   86     }
   87 
   88     void KeyfilesPanel::OnAddDirectoryButtonClick (wxCommandEvent& event)
   89     {
   90         DirectoryPath dir = Gui->SelectDirectory (this, LangString["SELECT_KEYFILE_PATH"]);
   91         if (!dir.IsEmpty())
   92         {
   93             vector <wstring> fields;
   94             fields.push_back (dir);
   95             Gui->AppendToListCtrl (KeyfilesListCtrl, fields);
   96             UpdateButtons();
   97         }
   98     }
   99 
  100     void KeyfilesPanel::OnAddFilesButtonClick (wxCommandEvent& event)
  101     {
  102         FilePathList files = Gui->SelectFiles (this, LangString["SELECT_KEYFILES"], false, true);
  103 
  104         foreach_ref (const FilePath &f, files)
  105         {
  106             vector <wstring> fields;
  107             fields.push_back (f);
  108             Gui->AppendToListCtrl (KeyfilesListCtrl, fields);
  109         }
  110         UpdateButtons();
  111     }
  112 
  113     void KeyfilesPanel::OnAddSecurityTokenSignatureButtonClick (wxCommandEvent& event)
  114     {
  115         try
  116         {
  117             SecurityTokenKeyfilesDialog dialog (this);
  118             if (dialog.ShowModal() == wxID_OK)
  119             {
  120                 foreach (const SecurityTokenKeyfilePath &path, dialog.GetSelectedSecurityTokenKeyfilePaths())
  121                 {
  122                     vector <wstring> fields;
  123                     fields.push_back (path);
  124                     Gui->AppendToListCtrl (KeyfilesListCtrl, fields);
  125                 }
  126 
  127                 UpdateButtons();
  128             }
  129         }
  130         catch (exception &e)
  131         {
  132             Gui->ShowError (e);
  133         }
  134     }
  135 
  136     void KeyfilesPanel::OnListSizeChanged (wxSizeEvent& event)
  137     {
  138         list <int> colPermilles;
  139         colPermilles.push_back (1000);
  140         Gui->SetListCtrlColumnWidths (KeyfilesListCtrl, colPermilles);
  141         event.Skip();
  142     }
  143 
  144     void KeyfilesPanel::OnRemoveAllButtonClick (wxCommandEvent& event)
  145     {
  146         KeyfilesListCtrl->DeleteAllItems();
  147         UpdateButtons();
  148     }
  149 
  150     void KeyfilesPanel::OnRemoveButtonClick (wxCommandEvent& event)
  151     {
  152         long offset = 0;
  153         foreach (long item, Gui->GetListCtrlSelectedItems (KeyfilesListCtrl))
  154             KeyfilesListCtrl->DeleteItem (item - offset++);
  155 
  156         UpdateButtons();
  157     }
  158 
  159     void KeyfilesPanel::UpdateButtons ()
  160     {
  161         RemoveAllButton->Enable (KeyfilesListCtrl->GetItemCount() > 0);
  162         RemoveButton->Enable (KeyfilesListCtrl->GetSelectedItemCount() > 0);
  163     }
  164 }