~ubuntu-branches/ubuntu/gutsy/audacity/gutsy-security

« back to all changes in this revision

Viewing changes to src/UploadDialog.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Free Ekanayaka
  • Date: 2007-05-18 12:11:05 UTC
  • mfrom: (1.2.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20070518121105-onhr7ojai3n5khzt
Tags: 1.3.3-1
* New upstream release
* Added watch file
* debian/patches:
   - updated libmp3lame patch
* debian/control:
   - as suggested upstream, depend on libgtk2.0-dev, otherwise 
     the code fails to build

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
#include "AllThemeResources.h"
50
50
#include "Project.h"
51
51
 
 
52
#include "FileDialog.h"
 
53
 
52
54
//#include "../images/AudacityLogo.xpm"
53
55
//#include "../images/UploadImages.h"
54
56
 
92
94
IMPLEMENT_CLASS(UploadDialog, wxDialog)
93
95
 
94
96
UploadDialog::UploadDialog(wxWindow * parent)
95
 
:  wxDialog(parent, -1, _("Audacity FTP"),
 
97
:  wxDialog(parent, -1, wxT("Audacity FTP"),
96
98
         wxDefaultPosition, wxSize(640, 480), wxDEFAULT_DIALOG_STYLE | wxWANTS_CHARS)
97
99
{
98
100
    ftp = NULL;
122
124
    icons->Add(*upIcon);
123
125
    
124
126
    wxFlexGridSizer *topSizer = new wxFlexGridSizer(2, 1);  
125
 
    wxStaticBoxSizer *connectionBox = new wxStaticBoxSizer(new wxStaticBox(this, -1, _("FTP Connection"), wxDefaultPosition, wxDefaultSize, 0, wxT("")), wxVERTICAL);   
126
 
    wxStaticBoxSizer *fileBox = new wxStaticBoxSizer(new wxStaticBox(this, -1, _("File Manager"), wxDefaultPosition, wxDefaultSize, 0, wxT("")), wxVERTICAL);
127
 
    wxStaticBoxSizer *siteBox = new wxStaticBoxSizer(new wxStaticBox(this, -1, _("Site Manager"), wxDefaultPosition, wxDefaultSize, 0, wxT("")), wxVERTICAL);
 
127
    wxStaticBoxSizer *connectionBox = new wxStaticBoxSizer(new wxStaticBox(this, -1, wxT("FTP Connection"), wxDefaultPosition, wxDefaultSize, 0, wxT("")), wxVERTICAL);   
 
128
    wxStaticBoxSizer *fileBox = new wxStaticBoxSizer(new wxStaticBox(this, -1, wxT("File Manager"), wxDefaultPosition, wxDefaultSize, 0, wxT("")), wxVERTICAL);
 
129
    wxStaticBoxSizer *siteBox = new wxStaticBoxSizer(new wxStaticBox(this, -1, wxT("Site Manager"), wxDefaultPosition, wxDefaultSize, 0, wxT("")), wxVERTICAL);
128
130
 
129
131
    wxFlexGridSizer *connectionSizer = new wxFlexGridSizer(2, 4);
130
132
    wxBoxSizer *leftSizer = new wxBoxSizer(wxVERTICAL);
138
140
    txtFtpHost = new wxTextCtrl(this, wxID_FTPHOST, wxT(""), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, wxT(""));
139
141
    txtFtpUser = new wxTextCtrl(this, wxID_FTPUSER, wxT(""), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, wxT(""));
140
142
    txtFtpPass = new wxTextCtrl(this, wxID_FTPPASS, wxT(""), wxDefaultPosition, wxDefaultSize, wxTE_PASSWORD, wxDefaultValidator, wxT(""));
141
 
    btnConnect = new wxButton(this, wxID_CONNECT, _("&Connect"), wxDefaultPosition, wxDefaultSize);
142
 
    btnDisconnect = new wxButton(this, wxID_DISCONNECT, _("&Disconnect"), wxDefaultPosition, wxDefaultSize);
 
143
    btnConnect = new wxButton(this, wxID_CONNECT, wxT("&Connect"), wxDefaultPosition, wxDefaultSize);
 
144
    btnDisconnect = new wxButton(this, wxID_DISCONNECT, wxT("&Disconnect"), wxDefaultPosition, wxDefaultSize);
143
145
    btnDisconnect->Enable(false);
144
146
 
145
 
    btnUploadFile = new wxButton(this, wxID_UPLOAD_FILE, _("Upload &File"), wxDefaultPosition, wxDefaultSize);
 
147
    btnUploadFile = new wxButton(this, wxID_UPLOAD_FILE, wxT("Upload &File"), wxDefaultPosition, wxDefaultSize);
146
148
    btnUploadFile->Enable(false);
147
 
    btnUploadDir = new wxButton(this, wxID_UPLOAD_DIR, _("Upload F&older"), wxDefaultPosition, wxDefaultSize);
 
149
    btnUploadDir = new wxButton(this, wxID_UPLOAD_DIR, wxT("Upload F&older"), wxDefaultPosition, wxDefaultSize);
148
150
    btnUploadDir->Enable(false);
149
 
    btnCreateDir = new wxButton(this, wxID_CREATEDIR, _("N&ew Folder"), wxDefaultPosition, wxDefaultSize);
 
151
    btnCreateDir = new wxButton(this, wxID_CREATEDIR, wxT("N&ew Folder"), wxDefaultPosition, wxDefaultSize);
150
152
    btnCreateDir->Enable(false);
151
153
 
152
 
    btnDelSite = new wxButton(this, wxID_DELSITE, _("&Remove Site"), wxDefaultPosition, wxDefaultSize);
 
154
    btnDelSite = new wxButton(this, wxID_DELSITE, wxT("&Remove Site"), wxDefaultPosition, wxDefaultSize);
153
155
 
154
156
    fileManager = new wxListView(this, wxID_FILEMANAGER, wxDefaultPosition, wxSize(350, 350), wxLC_REPORT, wxDefaultValidator, wxT(""));
155
157
    fileManager->AssignImageList(icons, wxIMAGE_LIST_SMALL);
156
158
    //fileManager->Show(false);
157
 
    fileManager->InsertColumn(0, _("name"));
158
 
    fileManager->InsertColumn(1, _("size (bytes)"));
159
 
    fileManager->InsertColumn(2, _("permissions"));
 
159
    fileManager->InsertColumn(0, wxT("Name"));
 
160
    fileManager->InsertColumn(1, wxT("Size (bytes)"));
 
161
    fileManager->InsertColumn(2, wxT("Permissions"));
160
162
 
161
163
    siteList = new wxListView(this, wxID_SITELIST, wxDefaultPosition, wxSize(200, 215), wxLC_REPORT | wxLC_NO_HEADER, wxDefaultValidator, wxT(""));
162
164
    siteList->InsertColumn(0, wxT(""));
163
165
 
164
 
    connectionSizer->Add(new wxStaticText(this, -1, _("Name:"), wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT, wxT("")));
 
166
    connectionSizer->Add(new wxStaticText(this, -1, wxT("Name:"), wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT, wxT("")));
165
167
    connectionSizer->Add(txtFtpName);
166
 
    connectionSizer->Add(new wxStaticText(this, -1, _("Host:"), wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT, wxT("")));
 
168
    connectionSizer->Add(new wxStaticText(this, -1, wxT("Host:"), wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT, wxT("")));
167
169
    connectionSizer->Add(txtFtpHost);
168
 
    connectionSizer->Add(new wxStaticText(this, -1, _("Username:"), wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT, wxT("")));
 
170
    connectionSizer->Add(new wxStaticText(this, -1, wxT("Username:"), wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT, wxT("")));
169
171
    connectionSizer->Add(txtFtpUser);
170
 
    connectionSizer->Add(new wxStaticText(this, -1, _("Password:"), wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT, wxT("")));
 
172
    connectionSizer->Add(new wxStaticText(this, -1, wxT("Password:"), wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT, wxT("")));
171
173
    connectionSizer->Add(txtFtpPass);
172
174
    connectionSizer->Add(btnConnect, 0, wxALIGN_LEFT | wxALL, 5);
173
175
    connectionSizer->Add(btnDisconnect, 0, wxALIGN_LEFT | wxALL, 5);
225
227
 
226
228
    wxString system;
227
229
 
228
 
    SetTitle(_("Connecting..."));
 
230
    SetTitle(wxT("Connecting..."));
229
231
    SetCursor(wxCURSOR_WAIT);
230
232
 
231
233
    //int connectionExists = -1;
247
249
        if (system.Find(wxT("unix"))==-1 && system.Find(wxT("windows"))==-1)
248
250
        {
249
251
            wxString msg;
250
 
            msg.Printf(_("Unknown FTP Server type: %s\n\nOnly Unix based and Windows systems are supported/tested at this time."), (const wxChar*)system);
251
 
            wxMessageBox(msg, _("Error"), wxOK | wxICON_INFORMATION, this);
 
252
            msg.Printf(wxT("Unknown FTP Server type: %s\n\nOnly Unix based and Windows systems are supported/tested at this time."), (const wxChar*)system);
 
253
            wxMessageBox(msg, wxT("Error"), wxOK | wxICON_INFORMATION, this);
252
254
        }
253
255
 
254
256
        btnConnect->Enable(false);
267
269
        txtFtpPass->Enable(false);
268
270
 
269
271
        if (txtFtpName->GetValue().Trim() == wxT(""))
270
 
            txtFtpName->SetValue(_("New Site"));
 
272
            txtFtpName->SetValue(wxT("New Site"));
271
273
 
272
274
        // save login into to connections file
273
275
        if (SaveFtpSite(txtFtpName->GetValue(), txtFtpHost->GetValue(), txtFtpUser->GetValue(), txtFtpPass->GetValue()))
277
279
            siteList->SetItemData(tmp, 0);
278
280
        }
279
281
 
280
 
        SetTitle(_("Connected to: ") + txtFtpHost->GetValue());
 
282
        SetTitle(wxT("Connected to: ") + txtFtpHost->GetValue());
281
283
    
282
284
        RefreshFiles();
283
285
        
285
287
 
286
288
    else
287
289
    {
288
 
        wxMessageBox(_("Connection cannot be established"), _("FTP Status"), wxOK | wxICON_INFORMATION, this);
289
 
        delete ftp;
 
290
        wxMessageBox(wxT("Connection cannot be established"), wxT("FTP Status"), wxOK | wxICON_INFORMATION, this);
 
291
      delete ftp;
 
292
      ftp = NULL;
290
293
    }
291
294
 
292
295
    SetCursor(wxCURSOR_ARROW);
296
299
void UploadDialog::OnDisconnect(wxCommandEvent & WXUNUSED(event))
297
300
{
298
301
 
299
 
    delete ftp;
 
302
   delete ftp;
 
303
   ftp = NULL;
 
304
 
300
305
 
301
306
    btnDisconnect->Enable(false);
302
307
    btnConnect->Enable(true);
314
319
    txtFtpUser->Enable(true);
315
320
    txtFtpPass->Enable(true);
316
321
 
317
 
    SetTitle(_("No Connection"));
 
322
    SetTitle(wxT("No Connection"));
318
323
    fileManager->Show(false);
319
324
 
320
325
    LoadFtpSiteList();
330
335
 
331
336
    abort = false;
332
337
 
333
 
    wxFileDialog *open = new wxFileDialog(this, _("Choose file(s) to upload"),
334
 
                                          ::wxGetCwd(), wxT(""),
335
 
                                          _("All files (*.*)|*.*"),
336
 
                                          wxOPEN | wxMULTIPLE); 
 
338
    FileDialog open(this, wxT("Choose file(s) to upload"),
 
339
                    ::wxGetCwd(), wxT(""),
 
340
                    wxT("All files (*.*)|*.*"),
 
341
                    wxOPEN | wxMULTIPLE); 
337
342
    
338
 
    if (open->ShowModal()==wxID_OK)
 
343
    if (open.ShowModal()==wxID_OK)
339
344
    {
340
345
        SetCursor(wxCURSOR_WAIT);
341
346
 
342
347
        // get the file(s) the user selected
343
 
        open->GetPaths(files);
 
348
        open.GetPaths(files);
344
349
 
345
350
        for (count = 0; count < files.GetCount(); count++)
346
351
        {   
367
372
void UploadDialog::OnUploadDir(wxCommandEvent & WXUNUSED(event))
368
373
{
369
374
 
370
 
    wxDirDialog *open = new wxDirDialog(this, _("Choose folder to upload"), wxT("")); 
371
 
    int result = open->ShowModal();
 
375
    wxDirDialog open(this, wxT("Choose folder to upload"), wxT("")); 
 
376
    int result = open.ShowModal();
372
377
 
373
378
    abort = false;
374
379
 
375
380
    if (result ==  wxID_OK)
376
381
    {
377
382
        SetCursor(wxCURSOR_WAIT);
378
 
        UploadDir(open->GetPath(), wxT(""));
 
383
        UploadDir(open.GetPath(), wxT(""));
379
384
        SetCursor(wxCURSOR_ARROW);
380
385
    }
381
386
}
386
391
    listIndex = event.m_itemIndex;
387
392
 
388
393
    wxMenu *menu = new wxMenu();
389
 
    wxMenuItem *del = new wxMenuItem(menu, wxID_POPUP_DELETE, _("Delete"), _("Delete file(s) from server"));
390
 
    wxMenuItem *rn  = new wxMenuItem(menu, wxID_POPUP_RENAME, _("Rename"), _("Rename file"));
391
 
    wxMenuItem *dl  = new wxMenuItem(menu, wxID_POPUP_DOWNLOAD, _("Download"), _("Download this file(s) to your computer"));
 
394
    wxMenuItem *del = new wxMenuItem(menu, wxID_POPUP_DELETE, wxT("Delete"), wxT("Delete file(s) from server"));
 
395
    wxMenuItem *rn  = new wxMenuItem(menu, wxID_POPUP_RENAME, wxT("Rename"), wxT("Rename file"));
 
396
    wxMenuItem *dl  = new wxMenuItem(menu, wxID_POPUP_DOWNLOAD, wxT("Download"), wxT("Download this file(s) to your computer"));
392
397
 
393
398
    wxMenuItem *sep  = new wxMenuItem(menu, -1, wxT(""), wxT(""));
394
399
 
443
448
        if (fileManager->GetSelectedItemCount() > 1)
444
449
        {
445
450
 
446
 
            int result = wxMessageBox(_("Delete selected items?"), _("Confirm"), wxYES_NO, NULL);
 
451
            int result = wxMessageBox(wxT("Delete selected items?"), wxT("Confirm"), wxYES_NO, NULL);
447
452
 
448
453
            if (result == wxYES)
449
454
            {
472
477
                        // if directory
473
478
                        if (selectPerm->Item(count).GetChar(0) == wxT('d'))
474
479
                        {
475
 
                            GetActiveProject()->ProgressShow(_("Deleting..."), wxT(""));
 
480
                            GetActiveProject()->ProgressShow(wxT("Deleting..."), wxT(""));
476
481
 
477
482
                            deleteFileList = new wxArrayString();
478
483
                            deleteDirList = new wxArrayString();
506
511
        {
507
512
 
508
513
            wxString confirm;
509
 
            confirm.Printf(_("Delete %s?"),
 
514
            confirm.Printf(wxT("Delete %s?"),
510
515
                           displayNames->Item(listIndex).c_str());
511
516
            
512
 
            int result = wxMessageBox(confirm, _("Confirm"), wxYES_NO, NULL);
 
517
            int result = wxMessageBox(confirm, wxT("Confirm"), wxYES_NO, NULL);
513
518
 
514
519
            if (result == wxYES)
515
520
            {
519
524
                    if (displayPerm->Item(listIndex).GetChar(0) == 'd')
520
525
                    {
521
526
                        // create progress bar
522
 
                        GetActiveProject()->ProgressShow(_("Delete"), wxT(""));
 
527
                        GetActiveProject()->ProgressShow(wxT("Delete"), wxT(""));
523
528
 
524
529
                        deleteFileList = new wxArrayString();
525
530
                        deleteDirList = new wxArrayString();    
547
552
 
548
553
    if (event.GetId() == wxID_POPUP_RENAME)
549
554
    {
550
 
        wxString result = wxGetTextFromUser(_("Please enter the new file/folder name:"), _("Rename"), fileManager->GetItemText(listIndex), this);
 
555
        wxString result = wxGetTextFromUser(wxT("Please enter the new file/folder name:"), wxT("Rename"), fileManager->GetItemText(listIndex), this);
551
556
 
552
557
        if (result != wxT(""))
553
558
        {
556
561
            if (ftp->Rename(fileManager->GetItemText(listIndex).MakeLower(), result))
557
562
                RefreshFiles();
558
563
            else
559
 
                wxMessageBox(_("Error renaming file, check permissions."), _("FTP Status"), wxOK, NULL);
 
564
                wxMessageBox(wxT("Error renaming file, check permissions."), wxT("FTP Status"), wxOK, NULL);
560
565
        }
561
566
    }
562
567
 
584
589
            }
585
590
 
586
591
            int percent = (int)(((float)count / (float)displayNames->GetCount())*1000.0);
587
 
            GetActiveProject()->ProgressUpdate(percent, _("Preparing to delete"));
 
592
            GetActiveProject()->ProgressUpdate(percent, wxT("Preparing to delete"));
588
593
        }
589
594
 
590
595
        deleteDirList->Add(ftp->Pwd());
604
609
        ftp->RmFile(files->Item(count));
605
610
        
606
611
        percent = (int)(((float)count / (float)files->GetCount())*1000.0);
607
 
        GetActiveProject()->ProgressUpdate(percent, _("Deleting files"));
 
612
        GetActiveProject()->ProgressUpdate(percent, wxT("Deleting files"));
608
613
    }
609
614
    
610
615
    for (count = 0; count < dirs->GetCount(); count++)
612
617
        ftp->RmDir(dirs->Item(count));
613
618
 
614
619
        percent = (int)(((float)count / (float)dirs->GetCount())*1000.0);
615
 
        GetActiveProject()->ProgressUpdate(percent, _("Deleting directories"));
 
620
        GetActiveProject()->ProgressUpdate(percent, wxT("Deleting directories"));
616
621
    }
617
622
 
618
623
}
699
704
        }
700
705
    }
701
706
    else
702
 
        wxMessageBox(_("Unable to retrieve directory contents."), _("FTP Status"), wxOK | wxICON_INFORMATION, this);
 
707
        wxMessageBox(wxT("Unable to retrieve directory contents."), wxT("FTP Status"), wxOK | wxICON_INFORMATION, this);
703
708
 
704
709
 
705
710
}
856
861
 
857
862
        if ( !in )
858
863
        {
859
 
                wxLogError(_("Could not get file: ")+src);
 
864
                wxLogError(wxT("Could not get file: ")+src);
860
865
        }
861
866
        else
862
867
        {
868
873
            else
869
874
                chunk = new char[size];
870
875
 
871
 
            GetActiveProject()->ProgressShow(_("Download Progress"), wxT(""));
 
876
            GetActiveProject()->ProgressShow(wxT("Download Progress"), wxT(""));
872
877
 
873
878
            // create output file
874
879
            out = new wxFileOutputStream(dest);
959
964
        chunk = new char[size];
960
965
 
961
966
    // create progress bar
962
 
    GetActiveProject()->ProgressShow(_("Upload Progress"), wxT(""));
 
967
    GetActiveProject()->ProgressShow(wxT("Upload Progress"), wxT(""));
963
968
 
964
969
    // find number of iterations needed
965
970
    if (size > CHUNKSIZE)
1153
1158
 
1154
1159
    }
1155
1160
    else
1156
 
        wxMessageBox(_("Cannot copy folder: ")+src, _("Error"), wxOK, NULL);
 
1161
        wxMessageBox(wxT("Cannot copy folder: ")+src, wxT("Error"), wxOK, NULL);
1157
1162
 
1158
1163
    }
1159
1164
 
1175
1180
 
1176
1181
        else
1177
1182
        {
1178
 
            wxDirDialog *saveDir = new wxDirDialog(this, _("Download Folder"), wxT(""));
 
1183
            wxDirDialog *saveDir = new wxDirDialog(this, wxT("Download Folder"), wxT(""));
1179
1184
            int result = saveDir->ShowModal();
1180
1185
 
1181
1186
            if (result == wxID_OK)
1193
1198
        }
1194
1199
        else
1195
1200
        {
1196
 
            wxFileDialog *saveFile = new wxFileDialog(this, _("Download File"),
1197
 
                                                      wxT(""), src,
1198
 
                                                      _("All Files (*.*)|*.*"), wxSAVE);
1199
 
            int result = saveFile->ShowModal();
 
1201
            FileDialog saveFile(this, wxT("Download File"),
 
1202
                                wxT(""), src,
 
1203
                                wxT("All files (*.*)|*.*"), wxSAVE);
 
1204
            int result = saveFile.ShowModal();
1200
1205
    
1201
1206
            if (result == wxID_OK)
1202
 
                DownloadFile(src, saveFile->GetPath());
 
1207
                DownloadFile(src, saveFile.GetPath());
1203
1208
        }
1204
1209
    }
1205
1210
}
1212
1217
    if (dir)
1213
1218
    {
1214
1219
        
1215
 
        wxDirDialog *saveDir = new wxDirDialog(this, _("Download Folder"), wxT(""));
1216
 
        int result = saveDir->ShowModal();
 
1220
        wxDirDialog saveDir(this, wxT("Download Folder"), wxT(""));
 
1221
        int result = saveDir.ShowModal();
1217
1222
 
1218
1223
        if (result == wxID_OK)
1219
 
            DownloadDir(src, saveDir->GetPath());
 
1224
            DownloadDir(src, saveDir.GetPath());
1220
1225
 
1221
1226
    }
1222
1227
    else
1223
1228
    {
1224
1229
 
1225
 
        wxFileDialog *saveFile = new wxFileDialog(this, _("Download File"), wxT(""), src, _("All Files (*.*)|*.*"), wxSAVE);
1226
 
        int result = saveFile->ShowModal();
 
1230
        FileDialog saveFile(this, wxT("Download File"), wxT(""), src, wxT("All files (*.*)|*.*"), wxSAVE);
 
1231
        int result = saveFile.ShowModal();
1227
1232
    
1228
1233
        if (result == wxID_OK)
1229
 
            DownloadFile(src, saveFile->GetPath());
 
1234
            DownloadFile(src, saveFile.GetPath());
1230
1235
        
1231
1236
    }
1232
1237
}
1237
1242
    long item = -1;
1238
1243
 
1239
1244
    // get save directory
1240
 
    wxDirDialog *saveDir = new wxDirDialog(this, _("Download Files"), wxT(""));
 
1245
    wxDirDialog *saveDir = new wxDirDialog(this, wxT("Download Files"), wxT(""));
1241
1246
    saveDir->ShowModal();
1242
1247
 
1243
1248
    // download selected items
1266
1271
void UploadDialog::OnCreateDir(wxCommandEvent &event)
1267
1272
{
1268
1273
 
1269
 
    wxString result = wxGetTextFromUser(_("Please enter new folder name:"), _("New Folder"), wxT(""), this);
 
1274
    wxString result = wxGetTextFromUser(wxT("Please enter new folder name:"), wxT("New Folder"), wxT(""), this);
1270
1275
 
1271
1276
    if (result != wxT(""))
1272
1277
    {
1286
1291
    int index;
1287
1292
    long tmp;
1288
1293
    wxListItem listItem;
1289
 
    wxString newSite = _("New Site");
 
1294
    wxString newSite = wxT("New Site");
1290
1295
    
1291
1296
    index = siteList->GetItemCount();
1292
1297