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

unix.superglobalmegacorp.com

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