~ubuntu-branches/ubuntu/vivid/guayadeque/vivid

« back to all changes in this revision

Viewing changes to .pc/05-wx3.0.patch/src/FileBrowser.cpp

  • Committer: Package Import Robot
  • Author(s): Artur Rona
  • Date: 2014-12-29 01:09:05 UTC
  • mfrom: (12.1.3 sid)
  • Revision ID: package-import@ubuntu.com-20141229010905-r5m8w9224bt0nm05
Tags: 0.3.7~ds0-2.1ubuntu1
* Merge from Debian unstable.  Remaining changes:
  - debian/control, debian/patches/05-diable-indicate.patch:
    + Disable indicator, as mpris only is needed for sound
      menu integration?!

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// -------------------------------------------------------------------------------- //
 
2
//      Copyright (C) 2008-2013 J.Rios
 
3
//      anonbeat@gmail.com
 
4
//
 
5
//    This Program is free software; you can redistribute it and/or modify
 
6
//    it under the terms of the GNU General Public License as published by
 
7
//    the Free Software Foundation; either version 3, or (at your option)
 
8
//    any later version.
 
9
//
 
10
//    This Program is distributed in the hope that it will be useful,
 
11
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
13
//    GNU General Public License for more details.
 
14
//
 
15
//    You should have received a copy of the GNU General Public License
 
16
//    along with this program; see the file LICENSE.  If not, write to
 
17
//    the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 
18
//    http://www.gnu.org/copyleft/gpl.html
 
19
//
 
20
// -------------------------------------------------------------------------------- //
 
21
#include "FileBrowser.h"
 
22
 
 
23
#include "Accelerators.h"
 
24
#include "AuiDockArt.h"
 
25
#include "Config.h"
 
26
#include "FileRenamer.h"
 
27
#include "Images.h"
 
28
#include "LibUpdate.h"
 
29
#include "MainFrame.h"
 
30
#include "PlayListAppend.h"
 
31
#include "TagInfo.h"
 
32
#include "TrackEdit.h"
 
33
#include "Utils.h"
 
34
 
 
35
#include <wx/aui/aui.h>
 
36
#include <wx/arrimpl.cpp>
 
37
#include <wx/artprov.h>
 
38
#include <wx/clipbrd.h>
 
39
 
 
40
WX_DEFINE_OBJARRAY(guFileItemArray);
 
41
 
 
42
// -------------------------------------------------------------------------------- //
 
43
guMediaViewer * FindMediaViewerByPath( guMainFrame * mainframe, const wxString curpath )
 
44
{
 
45
    const guMediaCollectionArray &Collections = mainframe->GetMediaCollections();
 
46
    int Index;
 
47
    int Count = Collections.Count();
 
48
    for( Index = 0; Index < Count; Index++ )
 
49
    {
 
50
        const guMediaCollection & Collection = Collections[ Index ];
 
51
        if( mainframe->IsCollectionActive( Collection.m_UniqueId ) )
 
52
        {
 
53
            int PathIndex;
 
54
            int PathCount = Collection.m_Paths.Count();
 
55
            for( PathIndex = 0; PathIndex < PathCount; PathIndex++ )
 
56
            {
 
57
                guLogMessage( wxT( "%s == %s" ), curpath.c_str(), Collection.m_Paths[ PathIndex ].c_str() );
 
58
                if( curpath.StartsWith( Collection.m_Paths[ PathIndex ] ) )
 
59
                {
 
60
                    return mainframe->FindCollectionMediaViewer( Collection.m_UniqueId );
 
61
                }
 
62
            }
 
63
        }
 
64
    }
 
65
    return NULL;
 
66
}
 
67
 
 
68
// -------------------------------------------------------------------------------- //
 
69
// guGenericDirCtrl
 
70
// -------------------------------------------------------------------------------- //
 
71
BEGIN_EVENT_TABLE(guGenericDirCtrl, wxGenericDirCtrl)
 
72
    EVT_TREE_BEGIN_LABEL_EDIT( wxID_ANY, guGenericDirCtrl::OnBeginRenameDir )
 
73
    EVT_TREE_END_LABEL_EDIT( wxID_ANY, guGenericDirCtrl::OnEndRenameDir )
 
74
END_EVENT_TABLE()
 
75
 
 
76
// -------------------------------------------------------------------------------- //
 
77
guGenericDirCtrl::guGenericDirCtrl( wxWindow * parent, guMainFrame * mainframe, const int showpaths  ) :
 
78
              wxGenericDirCtrl( parent, wxID_ANY, wxDirDialogDefaultFolderStr,
 
79
                wxDefaultPosition, wxDefaultSize, wxDIRCTRL_SELECT_FIRST|wxDIRCTRL_DIR_ONLY|wxDIRCTRL_3D_INTERNAL|wxNO_BORDER|wxDIRCTRL_EDIT_LABELS ,
 
80
                wxEmptyString, 0, wxTreeCtrlNameStr )
 
81
{
 
82
    m_MainFrame = mainframe;
 
83
    m_ShowPaths = showpaths;
 
84
    m_FileBrowserDirCtrl = ( guFileBrowserDirCtrl * ) parent;
 
85
    wxImageList * ImageList = GetTreeCtrl()->GetImageList();
 
86
    ImageList->Add( guImage( guIMAGE_INDEX_tiny_library ) );
 
87
    ImageList->Add( guImage( guIMAGE_INDEX_tiny_podcast ) );
 
88
    ImageList->Add( guImage( guIMAGE_INDEX_tiny_record ) );
 
89
 
 
90
    guConfig * Config = ( guConfig * ) guConfig::Get();
 
91
    Config->RegisterObject( this );
 
92
 
 
93
    Connect( ID_CONFIG_UPDATED, guConfigUpdatedEvent, wxCommandEventHandler( guGenericDirCtrl::OnConfigUpdated ), NULL, this );
 
94
}
 
95
 
 
96
// -------------------------------------------------------------------------------- //
 
97
guGenericDirCtrl::~guGenericDirCtrl()
 
98
{
 
99
    guConfig * Config = ( guConfig * ) guConfig::Get();
 
100
    Config->UnRegisterObject( this );
 
101
 
 
102
    Disconnect( ID_CONFIG_UPDATED, guConfigUpdatedEvent, wxCommandEventHandler( guGenericDirCtrl::OnConfigUpdated ), NULL, this );
 
103
}
 
104
 
 
105
// -------------------------------------------------------------------------------- //
 
106
void guGenericDirCtrl::OnConfigUpdated( wxCommandEvent &event )
 
107
{
 
108
    int Flags = event.GetInt();
 
109
    if( Flags & ( guPREFERENCE_PAGE_FLAG_LIBRARY | guPREFERENCE_PAGE_FLAG_RECORD | guPREFERENCE_PAGE_FLAG_PODCASTS ) )
 
110
    {
 
111
        if( m_ShowPaths != guFILEBROWSER_SHOWPATH_SYSTEM )
 
112
        {
 
113
            wxString CurPath = GetPath();
 
114
            ReCreateTree();
 
115
            SetPath( CurPath );
 
116
        }
 
117
    }
 
118
}
 
119
 
 
120
// -------------------------------------------------------------------------------- //
 
121
void guGenericDirCtrl::SetupSections()
 
122
{
 
123
    guConfig * Config = ( guConfig * ) guConfig::Get();
 
124
 
 
125
    if( m_ShowPaths & guFILEBROWSER_SHOWPATH_LOCATIONS )
 
126
    {
 
127
        const guMediaCollectionArray &  Collections = m_MainFrame->GetMediaCollections();
 
128
        int Index;
 
129
        int Count = Collections.Count();
 
130
        for( Index = 0; Index < Count; Index++ )
 
131
        {
 
132
            const guMediaCollection & Collection = Collections[ Index ];
 
133
            if( m_MainFrame->IsCollectionActive( Collection.m_UniqueId ) )
 
134
            {
 
135
                int PathIndex;
 
136
                int PathCount = Collection.m_Paths.Count();
 
137
                for( PathIndex = 0; PathIndex < PathCount; PathIndex++ )
 
138
                {
 
139
                    wxString LibName = Collection.m_Paths[ PathIndex ];
 
140
                    if( LibName.EndsWith( wxT( "/" ) ) )
 
141
                        LibName.RemoveLast();
 
142
                    AddSection( LibName, wxFileNameFromPath( LibName ), guDIR_IMAGE_INDEX_LIBRARY );
 
143
                }
 
144
            }
 
145
        }
 
146
 
 
147
        wxString Path = Config->ReadStr( wxT( "Path" ), wxEmptyString, wxT( "podcasts" ) );
 
148
        if( !Path.IsEmpty() )
 
149
        {
 
150
            wxString Name = Path;
 
151
            if( Name.EndsWith( wxT( "/" ) ) )
 
152
                Name.RemoveLast();
 
153
            AddSection( Path, wxFileNameFromPath( Name ), guDIR_IMAGE_INDEX_PODCASTS );
 
154
        }
 
155
 
 
156
        Path = Config->ReadStr( wxT( "Path" ), wxEmptyString, wxT( "record" ) );
 
157
        if( !Path.IsEmpty() )
 
158
        {
 
159
            wxString Name = Path;
 
160
            if( Name.EndsWith( wxT( "/" ) ) )
 
161
                Name.RemoveLast();
 
162
            AddSection( Path, wxFileNameFromPath( Name ), guDIR_IMAGE_INDEX_RECORDS );
 
163
        }
 
164
    }
 
165
    else //if( m_ShowPaths & guFILEBROWSER_SHOWPATH_SYSTEM )
 
166
    {
 
167
        AddSection( wxT( "/" ), wxT( "/" ), guDIR_IMAGE_INDEX_FOLDER );
 
168
    }
 
169
}
 
170
 
 
171
// -------------------------------------------------------------------------------- //
 
172
void guGenericDirCtrl::OnBeginRenameDir( wxTreeEvent &event )
 
173
{
 
174
    OnBeginEditItem( event );
 
175
}
 
176
 
 
177
// -------------------------------------------------------------------------------- //
 
178
void guGenericDirCtrl::OnEndRenameDir( wxTreeEvent &event )
 
179
{
 
180
    OnEndEditItem( event );
 
181
    wxTreeCtrl * TreeCtrl = GetTreeCtrl();
 
182
    TreeCtrl->SelectItem( m_RenameItemId );
 
183
    m_FileBrowserDirCtrl->RenamedDir( m_RenameName, GetPath() );
 
184
}
 
185
 
 
186
// -------------------------------------------------------------------------------- //
 
187
void guGenericDirCtrl::FolderRename( void )
 
188
{
 
189
    wxTreeCtrl * TreeCtrl = GetTreeCtrl();
 
190
    m_RenameItemId = TreeCtrl->GetSelection();
 
191
    m_RenameName = GetPath();
 
192
    TreeCtrl->EditLabel( m_RenameItemId );
 
193
}
 
194
 
 
195
// -------------------------------------------------------------------------------- //
 
196
// guFileBrowserDirCtrl
 
197
// -------------------------------------------------------------------------------- //
 
198
guFileBrowserDirCtrl::guFileBrowserDirCtrl( wxWindow * parent, guMainFrame * mainframe, guDbLibrary * db, const wxString &dirpath ) :
 
199
    wxPanel( parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL | wxNO_BORDER )
 
200
{
 
201
    m_MainFrame = mainframe;
 
202
    m_DefaultDb = db;
 
203
    m_Db = NULL;
 
204
    m_MediaViewer = NULL;
 
205
    m_AddingFolder = false;
 
206
 
 
207
    guConfig * Config = ( guConfig * ) guConfig::Get();
 
208
    Config->RegisterObject( this );
 
209
 
 
210
        wxBoxSizer * MainSizer;
 
211
        MainSizer = new wxBoxSizer( wxVERTICAL );
 
212
 
 
213
    int ShowPaths = Config->ReadNum( wxT( "ShowLibPaths" ), guFILEBROWSER_SHOWPATH_LOCATIONS, wxT( "filebrowser" ) );
 
214
        m_DirCtrl = new guGenericDirCtrl( this, m_MainFrame, ShowPaths );
 
215
        m_DirCtrl->ShowHidden( false );
 
216
        SetPath( dirpath, FindMediaViewerByPath( m_MainFrame, dirpath ) );
 
217
        MainSizer->Add( m_DirCtrl, 1, wxEXPAND, 5 );
 
218
 
 
219
        wxBoxSizer * DirBtnSizer = new wxBoxSizer( wxHORIZONTAL );
 
220
 
 
221
 
 
222
        DirBtnSizer->Add( 0, 0, 1, wxEXPAND, 5 );
 
223
 
 
224
        m_ShowLibPathsBtn = new wxToggleBitmapButton( this, wxID_ANY, guImage( guIMAGE_INDEX_tiny_library ), wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW );
 
225
    m_ShowLibPathsBtn->SetToolTip( ShowPaths == guFILEBROWSER_SHOWPATH_SYSTEM ?
 
226
                          _( "See used locations" ) :
 
227
                          _( "See system files" ) );
 
228
        m_ShowLibPathsBtn->SetValue( ShowPaths & guFILEBROWSER_SHOWPATH_LOCATIONS );
 
229
        DirBtnSizer->Add( m_ShowLibPathsBtn, 0, wxTOP|wxBOTTOM|wxRIGHT, 5 );
 
230
 
 
231
        MainSizer->Add( DirBtnSizer, 0, wxEXPAND, 5 );
 
232
 
 
233
        this->SetSizer( MainSizer );
 
234
        this->Layout();
 
235
 
 
236
    m_DirCtrl->Connect( wxEVT_COMMAND_TREE_ITEM_MENU, wxTreeEventHandler( guFileBrowserDirCtrl::OnContextMenu ), NULL, this );
 
237
        m_ShowLibPathsBtn->Connect( wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, wxCommandEventHandler( guFileBrowserDirCtrl::OnShowLibPathsClick ), NULL, this );
 
238
 
 
239
    Connect( ID_CONFIG_UPDATED, guConfigUpdatedEvent, wxCommandEventHandler( guFileBrowserDirCtrl::OnConfigUpdated ), NULL, this );
 
240
 
 
241
    CreateAcceleratorTable();
 
242
}
 
243
 
 
244
// -------------------------------------------------------------------------------- //
 
245
guFileBrowserDirCtrl::~guFileBrowserDirCtrl()
 
246
{
 
247
    guConfig * Config = ( guConfig * ) guConfig::Get();
 
248
    Config->UnRegisterObject( this );
 
249
 
 
250
    Config->WriteNum( wxT( "ShowLibPaths" ), m_ShowLibPathsBtn->GetValue(), wxT( "filebrowser" ) );
 
251
    m_DirCtrl->Disconnect( wxEVT_COMMAND_TREE_ITEM_MENU, wxTreeEventHandler( guFileBrowserDirCtrl::OnContextMenu ), NULL, this );
 
252
        m_ShowLibPathsBtn->Disconnect( wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, wxCommandEventHandler( guFileBrowserDirCtrl::OnShowLibPathsClick ), NULL, this );
 
253
 
 
254
    Disconnect( ID_CONFIG_UPDATED, guConfigUpdatedEvent, wxCommandEventHandler( guFileBrowserDirCtrl::OnConfigUpdated ), NULL, this );
 
255
}
 
256
 
 
257
// -------------------------------------------------------------------------------- //
 
258
void guFileBrowserDirCtrl::OnConfigUpdated( wxCommandEvent &event )
 
259
{
 
260
    int Flags = event.GetInt();
 
261
    if( Flags & guPREFERENCE_PAGE_FLAG_ACCELERATORS )
 
262
    {
 
263
        CreateAcceleratorTable();
 
264
    }
 
265
}
 
266
 
 
267
// -------------------------------------------------------------------------------- //
 
268
void guFileBrowserDirCtrl::CreateAcceleratorTable( void )
 
269
{
 
270
    wxAcceleratorTable AccelTable;
 
271
    wxArrayInt AliasAccelCmds;
 
272
    wxArrayInt RealAccelCmds;
 
273
 
 
274
    AliasAccelCmds.Add( ID_PLAYER_PLAYLIST_SAVE );
 
275
    AliasAccelCmds.Add( ID_PLAYER_PLAYLIST_EDITTRACKS );
 
276
    AliasAccelCmds.Add( ID_TRACKS_PLAY );
 
277
    AliasAccelCmds.Add( ID_TRACKS_ENQUEUE_AFTER_ALL );
 
278
    AliasAccelCmds.Add( ID_TRACKS_ENQUEUE_AFTER_TRACK );
 
279
    AliasAccelCmds.Add( ID_TRACKS_ENQUEUE_AFTER_ALBUM );
 
280
    AliasAccelCmds.Add( ID_TRACKS_ENQUEUE_AFTER_ARTIST );
 
281
 
 
282
    RealAccelCmds.Add( ID_FILESYSTEM_FOLDER_SAVEPLAYLIST );
 
283
    RealAccelCmds.Add( ID_FILESYSTEM_FOLDER_EDITTRACKS );
 
284
    RealAccelCmds.Add( ID_FILESYSTEM_FOLDER_PLAY );
 
285
    RealAccelCmds.Add( ID_FILESYSTEM_FOLDER_ENQUEUE_AFTER_ALL );
 
286
    RealAccelCmds.Add( ID_FILESYSTEM_FOLDER_ENQUEUE_AFTER_TRACK );
 
287
    RealAccelCmds.Add( ID_FILESYSTEM_FOLDER_ENQUEUE_AFTER_ALBUM );
 
288
    RealAccelCmds.Add( ID_FILESYSTEM_FOLDER_ENQUEUE_AFTER_ARTIST );
 
289
 
 
290
    if( guAccelDoAcceleratorTable( AliasAccelCmds, RealAccelCmds, AccelTable ) )
 
291
    {
 
292
        SetAcceleratorTable( AccelTable );
 
293
    }
 
294
}
 
295
 
 
296
// -------------------------------------------------------------------------------- //
 
297
void AppendFolderCommands( wxMenu * menu )
 
298
{
 
299
    wxMenu * SubMenu;
 
300
    int Index;
 
301
    int Count;
 
302
    wxMenuItem * MenuItem;
 
303
 
 
304
    SubMenu = new wxMenu();
 
305
 
 
306
    guConfig * Config = ( guConfig * ) guConfig::Get();
 
307
    wxArrayString Commands = Config->ReadAStr( wxT( "Exec" ), wxEmptyString, wxT( "commands/execs" ) );
 
308
    wxArrayString Names = Config->ReadAStr( wxT( "Name" ), wxEmptyString, wxT( "commands/names" ) );
 
309
    if( ( Count = Commands.Count() ) )
 
310
    {
 
311
        for( Index = 0; Index < Count; Index++ )
 
312
        {
 
313
            if( ( Commands[ Index ].Find( wxT( "{bc}" ) ) == wxNOT_FOUND ) )
 
314
            {
 
315
                MenuItem = new wxMenuItem( menu, ID_COMMANDS_BASE + Index, Names[ Index ], Commands[ Index ] );
 
316
                SubMenu->Append( MenuItem );
 
317
            }
 
318
        }
 
319
 
 
320
        SubMenu->AppendSeparator();
 
321
    }
 
322
    else
 
323
    {
 
324
        MenuItem = new wxMenuItem( SubMenu, ID_MENU_PREFERENCES_COMMANDS, _( "Preferences" ), _( "Add commands in preferences" ) );
 
325
        SubMenu->Append( MenuItem );
 
326
    }
 
327
    menu->AppendSubMenu( SubMenu, _( "Commands" ) );
 
328
}
 
329
 
 
330
// -------------------------------------------------------------------------------- //
 
331
void guFileBrowserDirCtrl::OnContextMenu( wxTreeEvent &event )
 
332
{
 
333
    wxMenu Menu;
 
334
    wxMenuItem * MenuItem;
 
335
 
 
336
    wxPoint Point = event.GetPoint();
 
337
 
 
338
    MenuItem = new wxMenuItem( &Menu, ID_FILESYSTEM_FOLDER_PLAY,
 
339
                            wxString( _( "Play" ) ) + guAccelGetCommandKeyCodeString( ID_TRACKS_PLAY ),
 
340
                            _( "Play the selected folder" ) );
 
341
    MenuItem->SetBitmap( guImage( guIMAGE_INDEX_player_tiny_light_play ) );
 
342
    Menu.Append( MenuItem );
 
343
 
 
344
    MenuItem = new wxMenuItem( &Menu, ID_FILESYSTEM_FOLDER_ENQUEUE_AFTER_ALL,
 
345
                            wxString( _( "Enqueue" ) ) + guAccelGetCommandKeyCodeString( ID_TRACKS_ENQUEUE_AFTER_ALL ),
 
346
                            _( "Add the selected folder to playlist" ) );
 
347
    MenuItem->SetBitmap( guImage( guIMAGE_INDEX_tiny_add ) );
 
348
    Menu.Append( MenuItem );
 
349
 
 
350
    wxMenu * EnqueueMenu = new wxMenu();
 
351
 
 
352
    MenuItem = new wxMenuItem( EnqueueMenu, ID_FILESYSTEM_FOLDER_ENQUEUE_AFTER_TRACK,
 
353
                            wxString( _( "Current Track" ) ) +  guAccelGetCommandKeyCodeString( ID_TRACKS_ENQUEUE_AFTER_TRACK ),
 
354
                            _( "Add current selected tracks to playlist after the current track" ) );
 
355
    MenuItem->SetBitmap( guImage( guIMAGE_INDEX_tiny_add ) );
 
356
    EnqueueMenu->Append( MenuItem );
 
357
 
 
358
    MenuItem = new wxMenuItem( EnqueueMenu, ID_FILESYSTEM_FOLDER_ENQUEUE_AFTER_ALBUM,
 
359
                            wxString( _( "Current Album" ) ) +  guAccelGetCommandKeyCodeString( ID_TRACKS_ENQUEUE_AFTER_ALBUM ),
 
360
                            _( "Add current selected tracks to playlist after the current album" ) );
 
361
    MenuItem->SetBitmap( guImage( guIMAGE_INDEX_tiny_add ) );
 
362
    EnqueueMenu->Append( MenuItem );
 
363
 
 
364
    MenuItem = new wxMenuItem( EnqueueMenu, ID_FILESYSTEM_FOLDER_ENQUEUE_AFTER_ARTIST,
 
365
                            wxString( _( "Current Artist" ) ) +  guAccelGetCommandKeyCodeString( ID_TRACKS_ENQUEUE_AFTER_ARTIST ),
 
366
                            _( "Add current selected tracks to playlist after the current artist" ) );
 
367
    MenuItem->SetBitmap( guImage( guIMAGE_INDEX_tiny_add ) );
 
368
    EnqueueMenu->Append( MenuItem );
 
369
 
 
370
    Menu.Append( wxID_ANY, _( "Enqueue After" ), EnqueueMenu );
 
371
 
 
372
    Menu.AppendSeparator();
 
373
 
 
374
    MenuItem = new wxMenuItem( &Menu, ID_FILESYSTEM_FOLDER_EDITTRACKS,
 
375
                            wxString( _( "Edit Tracks" ) ) + guAccelGetCommandKeyCodeString( ID_PLAYER_PLAYLIST_EDITTRACKS ),
 
376
                            _( "Edit the tracks in the selected folder" ) );
 
377
    MenuItem->SetBitmap( guImage( guIMAGE_INDEX_tiny_edit ) );
 
378
    Menu.Append( MenuItem );
 
379
 
 
380
    Menu.AppendSeparator();
 
381
 
 
382
    MenuItem = new wxMenuItem( &Menu, ID_FILESYSTEM_FOLDER_SAVEPLAYLIST,
 
383
                            wxString( _( "Save to Playlist" ) ) + guAccelGetCommandKeyCodeString( ID_PLAYER_PLAYLIST_SAVE ),
 
384
                            _( "Add the tracks in the selected folder to a playlist" ) );
 
385
    MenuItem->SetBitmap( guImage( guIMAGE_INDEX_tiny_doc_save ) );
 
386
    Menu.Append( MenuItem );
 
387
 
 
388
    Menu.AppendSeparator();
 
389
 
 
390
    MenuItem = new wxMenuItem( &Menu, ID_FILESYSTEM_FOLDER_COPY,
 
391
                            _( "Copy" ),
 
392
                            _( "Copy the selected folder to clipboard" ) );
 
393
    MenuItem->SetBitmap( guImage( guIMAGE_INDEX_tiny_edit_copy ) );
 
394
    Menu.Append( MenuItem );
 
395
    //MenuItem->Enable( false );
 
396
 
 
397
    MenuItem = new wxMenuItem( &Menu, ID_FILESYSTEM_FOLDER_PASTE,
 
398
                            _( "Paste" ),
 
399
                            _( "Paste to the selected folder" ) );
 
400
    Menu.Append( MenuItem );
 
401
    wxTheClipboard->UsePrimarySelection( false );
 
402
    if( wxTheClipboard->Open() )
 
403
    {
 
404
        if( wxTheClipboard->IsSupported( wxDF_FILENAME ) )
 
405
        {
 
406
            wxFileDataObject data;
 
407
            MenuItem->Enable( wxTheClipboard->GetData( data ) );
 
408
        }
 
409
        wxTheClipboard->Close();
 
410
    }
 
411
 
 
412
    Menu.AppendSeparator();
 
413
 
 
414
    MenuItem = new wxMenuItem( &Menu, ID_FILESYSTEM_FOLDER_NEW, _( "New Folder" ), _( "Create a new folder" ) );
 
415
    Menu.Append( MenuItem );
 
416
 
 
417
    MenuItem = new wxMenuItem( &Menu, ID_FILESYSTEM_FOLDER_RENAME, _( "Rename" ), _( "Rename the selected folder" ) );
 
418
    MenuItem->SetBitmap( guImage( guIMAGE_INDEX_tiny_edit ) );
 
419
    Menu.Append( MenuItem );
 
420
 
 
421
    MenuItem = new wxMenuItem( &Menu, ID_FILESYSTEM_FOLDER_DELETE, _( "Remove" ), _( "Remove the selected folder" ) );
 
422
    MenuItem->SetBitmap( guImage( guIMAGE_INDEX_tiny_edit_clear ) );
 
423
    Menu.Append( MenuItem );
 
424
 
 
425
    Menu.AppendSeparator();
 
426
 
 
427
    m_MainFrame->CreateCopyToMenu( &Menu );
 
428
 
 
429
    AppendFolderCommands( &Menu );
 
430
 
 
431
    PopupMenu( &Menu, Point );
 
432
    event.Skip();
 
433
}
 
434
 
 
435
// -------------------------------------------------------------------------------- //
 
436
void guFileBrowserDirCtrl::RenamedDir( const wxString &oldname, const wxString &newname )
 
437
{
 
438
    guLogMessage( wxT( "'%s' -> '%s'  (%i)" ), oldname.c_str(), newname.c_str(), m_Db != NULL );
 
439
 
 
440
    if( m_AddingFolder )
 
441
    {
 
442
        wxTreeCtrl * TreeCtrl = m_DirCtrl->GetTreeCtrl();
 
443
        if( newname.IsEmpty() )
 
444
        {
 
445
            TreeCtrl->Delete( TreeCtrl->GetSelection() );
 
446
        }
 
447
        //m_DirCtrl->ReCreateTree();
 
448
        m_AddingFolder = false;
 
449
    }
 
450
    else
 
451
    {
 
452
        if( oldname != newname )
 
453
        {
 
454
            if( m_Db )
 
455
                m_Db->UpdatePaths( oldname, newname );
 
456
            else
 
457
                m_DefaultDb->UpdatePaths( oldname, newname );
 
458
        }
 
459
    }
 
460
}
 
461
 
 
462
// -------------------------------------------------------------------------------- //
 
463
void guFileBrowserDirCtrl::FolderNew( void )
 
464
{
 
465
    wxTreeCtrl * TreeCtrl = m_DirCtrl->GetTreeCtrl();
 
466
    wxTreeItemId FolderParent = TreeCtrl->GetSelection();
 
467
    if( FolderParent.IsOk() )
 
468
    {
 
469
        m_AddingFolder = true;
 
470
 
 
471
        wxString NewDirName = GetPath() + _( "New Folder" );
 
472
        int Index = 1;
 
473
        while( wxDirExists( NewDirName ) )
 
474
        {
 
475
            NewDirName = GetPath() + _( "New Folder" );
 
476
            NewDirName += wxString::Format( wxT( "%i" ), Index++ );
 
477
        }
 
478
 
 
479
        if( wxMkdir( NewDirName, 0770 ) )
 
480
        {
 
481
            TreeCtrl->Collapse( FolderParent );
 
482
            //TreeCtrl->Expand( m_AddFolderParent );
 
483
            if( m_DirCtrl->ExpandPath( NewDirName ) )
 
484
            {
 
485
                wxTreeItemId Selected = TreeCtrl->GetSelection();
 
486
                if( Selected.IsOk() )
 
487
                {
 
488
                    wxTextCtrl * TextCtrl = TreeCtrl->EditLabel( Selected );
 
489
                    if( TextCtrl )
 
490
                    {
 
491
                        TextCtrl->SetSelection( -1, -1 );
 
492
                    }
 
493
                }
 
494
                else
 
495
                {
 
496
                    guLogMessage( wxT( "No Selected item" ) );
 
497
                }
 
498
            }
 
499
        }
 
500
        else
 
501
        {
 
502
            guLogError( wxT( "Could not create the new directory" ) );
 
503
        }
 
504
    }
 
505
}
 
506
 
 
507
// -------------------------------------------------------------------------------- //
 
508
bool RemoveDirItems( const wxString &path, wxArrayString * deletefiles )
 
509
{
 
510
    wxString FileName;
 
511
    wxString CurPath = path;
 
512
    if( !CurPath.EndsWith( wxT( "/" ) ) )
 
513
        CurPath += wxT( "/" );
 
514
    //guLogMessage( wxT( "Deleting folder %s" ), CurPath.c_str() );
 
515
    wxDir Dir( CurPath );
 
516
    if( Dir.IsOpened() )
 
517
    {
 
518
        if( Dir.GetFirst( &FileName, wxEmptyString, wxDIR_FILES | wxDIR_HIDDEN | wxDIR_DIRS | wxDIR_DOTDOT ) )
 
519
        {
 
520
            do {
 
521
                if( FileName != wxT( "." ) && FileName != wxT( ".." ) )
 
522
                {
 
523
                    if( wxDirExists( CurPath + FileName ) )
 
524
                    {
 
525
                        if( !RemoveDirItems( CurPath + FileName, deletefiles ) )
 
526
                            return false;
 
527
                        //guLogMessage( wxT( "Removing Dir: %s" ), ( CurPath + FileName ).c_str() );
 
528
                        if( !wxRmdir( CurPath + FileName ) )
 
529
                            return false;
 
530
                    }
 
531
                    else
 
532
                    {
 
533
                        //guLogMessage( wxT( "Removing file: %s" ), ( CurPath + FileName ).c_str() );
 
534
                        if( !wxRemoveFile( CurPath + FileName ) )
 
535
                            return false;
 
536
                        deletefiles->Add( CurPath + FileName );
 
537
                    }
 
538
                }
 
539
            } while( Dir.GetNext( &FileName ) );
 
540
        }
 
541
        return true;
 
542
    }
 
543
    return false;
 
544
}
 
545
 
 
546
// -------------------------------------------------------------------------------- //
 
547
void guFileBrowserDirCtrl::FolderDelete( void )
 
548
{
 
549
    wxTreeCtrl * TreeCtrl = m_DirCtrl->GetTreeCtrl();
 
550
    wxTreeItemId FolderId = TreeCtrl->GetSelection();
 
551
    wxDirItemData * FolderData = ( wxDirItemData *  ) TreeCtrl->GetItemData( FolderId );
 
552
    if( wxMessageBox( _( "Are you sure to delete the selected path ?" ),
 
553
                     _( "Confirm" ),
 
554
                     wxICON_QUESTION | wxYES_NO, this ) == wxYES )
 
555
    {
 
556
        wxArrayString DeleteFiles;
 
557
        if( RemoveDirItems( FolderData->m_path, &DeleteFiles ) && wxRmdir( FolderData->m_path ) )
 
558
        {
 
559
            TreeCtrl->Delete( FolderId );
 
560
        }
 
561
        else
 
562
        {
 
563
            wxMessageBox( _( "Error deleting the folder " ) + FolderData->m_path,
 
564
                _( "Error" ), wxICON_ERROR | wxOK, this );
 
565
        }
 
566
        //m_Db->DoCleanUp();
 
567
        if( m_Db )
 
568
            m_Db->CleanFiles( DeleteFiles );
 
569
        else
 
570
            m_DefaultDb->CleanFiles( DeleteFiles );
 
571
    }
 
572
}
 
573
 
 
574
 
 
575
// -------------------------------------------------------------------------------- //
 
576
void guFileBrowserDirCtrl::OnShowLibPathsClick( wxCommandEvent& event )
 
577
{
 
578
    int ShowPaths = m_ShowLibPathsBtn->GetValue();
 
579
 
 
580
    wxString CurPath = GetPath();
 
581
    m_DirCtrl->SetShowPaths( ShowPaths );
 
582
    m_DirCtrl->ReCreateTree();
 
583
    m_DirCtrl->SetPath( CurPath );
 
584
 
 
585
    m_ShowLibPathsBtn->SetToolTip( ShowPaths == guFILEBROWSER_SHOWPATH_SYSTEM ?
 
586
                          _( "See used locations" ) :
 
587
                          _( "See system files" ) );
 
588
}
 
589
 
 
590
 
 
591
// -------------------------------------------------------------------------------- //
 
592
void guFileBrowserDirCtrl::CollectionsUpdated( void )
 
593
{
 
594
    if( m_DirCtrl->GetShowPaths() & guFILEBROWSER_SHOWPATH_LOCATIONS )
 
595
    {
 
596
        wxString CurPath = GetPath();
 
597
        m_DirCtrl->ReCreateTree();
 
598
        m_DirCtrl->SetPath( CurPath );
 
599
    }
 
600
}
 
601
 
 
602
// -------------------------------------------------------------------------------- //
 
603
void guFileBrowserDirCtrl::SetPath( const wxString &path, guMediaViewer * mediaviewer )
 
604
{
 
605
    guLogMessage( wxT( "guFileBrowserDirCtrl::SetPath( %s )" ), path.c_str() );
 
606
    m_MediaViewer = mediaviewer;
 
607
    m_Db = mediaviewer ? mediaviewer->GetDb() : NULL;
 
608
    m_DirCtrl->SetPath( path );
 
609
}
 
610
 
 
611
// -------------------------------------------------------------------------------- //
 
612
void guFileBrowserDirCtrl::SetMediaViewer( guMediaViewer * mediaviewer )
 
613
{
 
614
    m_MediaViewer = mediaviewer;
 
615
    m_Db = mediaviewer ? mediaviewer->GetDb() : NULL;
 
616
}
 
617
 
 
618
// -------------------------------------------------------------------------------- //
 
619
// guFilesListBox
 
620
// -------------------------------------------------------------------------------- //
 
621
bool guAddDirItems( const wxString &path, wxArrayString &files )
 
622
{
 
623
    wxString FileName;
 
624
    wxString CurPath = path;
 
625
    if( !CurPath.EndsWith( wxT( "/" ) ) )
 
626
        CurPath += wxT( "/" );
 
627
    guLogMessage( wxT( "Searching in folder %s" ), CurPath.c_str() );
 
628
    wxDir Dir( CurPath );
 
629
    if( Dir.IsOpened() )
 
630
    {
 
631
        if( Dir.GetFirst( &FileName, wxEmptyString, wxDIR_FILES | wxDIR_HIDDEN | wxDIR_DIRS | wxDIR_DOTDOT ) )
 
632
        {
 
633
            do {
 
634
                if( FileName != wxT( "." ) && FileName != wxT( ".." ) )
 
635
                {
 
636
                    if( wxDirExists( CurPath + FileName ) )
 
637
                    {
 
638
                        if( !guAddDirItems( CurPath + FileName, files ) )
 
639
                            return false;
 
640
                    }
 
641
                    else
 
642
                    {
 
643
                        files.Add( CurPath + FileName );
 
644
                    }
 
645
                }
 
646
            } while( Dir.GetNext( &FileName ) );
 
647
        }
 
648
        return true;
 
649
    }
 
650
    return false;
 
651
}
 
652
 
 
653
// -------------------------------------------------------------------------------- //
 
654
guFilesListBox::guFilesListBox( wxWindow * parent, guDbLibrary * db ) :
 
655
    guListView( parent, wxLB_MULTIPLE | guLISTVIEW_COLUMN_SELECT | guLISTVIEW_COLUMN_SORTING | guLISTVIEW_ALLOWDRAG )
 
656
{
 
657
    m_Db = db;
 
658
 
 
659
    guConfig * Config = ( guConfig * ) guConfig::Get();
 
660
    Config->RegisterObject( this );
 
661
 
 
662
    m_Order = Config->ReadNum( wxT( "Order" ), 0, wxT( "filebrowser" ) );
 
663
    m_OrderDesc = Config->ReadNum( wxT( "OrderDesc" ), false, wxT( "filebrowser" ) );
 
664
 
 
665
    int ColId;
 
666
    wxString ColName;
 
667
    wxArrayString ColumnNames = GetColumnNames();
 
668
    int index;
 
669
    int count = ColumnNames.Count();
 
670
    for( index = 0; index < count; index++ )
 
671
    {
 
672
        ColId = Config->ReadNum( wxString::Format( wxT( "Id%u" ), index ), index, wxT( "filebrowser/columns/ids" ) );
 
673
 
 
674
        ColName = ColumnNames[ ColId ];
 
675
 
 
676
        ColName += ( ( ColId == m_Order ) ? ( m_OrderDesc ? wxT( " ▼" ) : wxT( " ▲" ) ) : wxEmptyString );
 
677
 
 
678
        guListViewColumn * Column = new guListViewColumn(
 
679
            ColName,
 
680
            ColId,
 
681
            Config->ReadNum( wxString::Format( wxT( "Width%u" ), index ), 80, wxT( "filebrowser/columns/widths" ) ),
 
682
            Config->ReadBool( wxString::Format( wxT( "Show%u" ), index ), true, wxT( "filebrowser/columns/shows" ) )
 
683
            );
 
684
        InsertColumn( Column );
 
685
    }
 
686
 
 
687
    Connect( ID_CONFIG_UPDATED, guConfigUpdatedEvent, wxCommandEventHandler( guFilesListBox::OnConfigUpdated ), NULL, this );
 
688
 
 
689
    CreateAcceleratorTable();
 
690
 
 
691
    ReloadItems();
 
692
}
 
693
 
 
694
 
 
695
// -------------------------------------------------------------------------------- //
 
696
guFilesListBox::~guFilesListBox()
 
697
{
 
698
    guConfig * Config = ( guConfig * ) guConfig::Get();
 
699
    Config->UnRegisterObject( this );
 
700
 
 
701
    wxArrayString ColumnNames = GetColumnNames();
 
702
    int index;
 
703
    int count = ColumnNames.Count();
 
704
    for( index = 0; index < count; index++ )
 
705
    {
 
706
        Config->WriteNum( wxString::Format( wxT( "Id%u" ), index ),
 
707
                          ( * m_Columns )[ index ].m_Id, wxT( "filebrowser/columns/ids" ) );
 
708
        Config->WriteNum( wxString::Format( wxT( "Width%u" ), index ),
 
709
                          ( * m_Columns )[ index ].m_Width, wxT( "filebrowser/columns/widths" ) );
 
710
        Config->WriteBool( wxString::Format( wxT( "Show%u" ), index ),
 
711
                           ( * m_Columns )[ index ].m_Enabled, wxT( "filebrowser/columns/shows" ) );
 
712
    }
 
713
 
 
714
    Config->WriteNum( wxT( "Order" ), m_Order, wxT( "filebrowser" ) );
 
715
    Config->WriteBool( wxT( "OrderDesc" ), m_OrderDesc, wxT( "filebrowser" ) );
 
716
 
 
717
    Disconnect( ID_CONFIG_UPDATED, guConfigUpdatedEvent, wxCommandEventHandler( guFilesListBox::OnConfigUpdated ), NULL, this );
 
718
}
 
719
 
 
720
// -------------------------------------------------------------------------------- //
 
721
void guFilesListBox::OnConfigUpdated( wxCommandEvent &event )
 
722
{
 
723
    int Flags = event.GetInt();
 
724
    if( Flags & guPREFERENCE_PAGE_FLAG_ACCELERATORS )
 
725
    {
 
726
        CreateAcceleratorTable();
 
727
    }
 
728
}
 
729
 
 
730
// -------------------------------------------------------------------------------- //
 
731
void guFilesListBox::CreateAcceleratorTable( void )
 
732
{
 
733
    wxAcceleratorTable AccelTable;
 
734
    wxArrayInt AliasAccelCmds;
 
735
    wxArrayInt RealAccelCmds;
 
736
 
 
737
    AliasAccelCmds.Add( ID_PLAYER_PLAYLIST_SAVE );
 
738
    AliasAccelCmds.Add( ID_PLAYER_PLAYLIST_EDITTRACKS );
 
739
    AliasAccelCmds.Add( ID_TRACKS_PLAY );
 
740
    AliasAccelCmds.Add( ID_TRACKS_ENQUEUE_AFTER_ALL );
 
741
    AliasAccelCmds.Add( ID_TRACKS_ENQUEUE_AFTER_TRACK );
 
742
    AliasAccelCmds.Add( ID_TRACKS_ENQUEUE_AFTER_ALBUM );
 
743
    AliasAccelCmds.Add( ID_TRACKS_ENQUEUE_AFTER_ARTIST );
 
744
 
 
745
    RealAccelCmds.Add( ID_FILESYSTEM_ITEMS_SAVEPLAYLIST );
 
746
    RealAccelCmds.Add( ID_FILESYSTEM_ITEMS_EDITTRACKS );
 
747
    RealAccelCmds.Add( ID_FILESYSTEM_ITEMS_PLAY );
 
748
    RealAccelCmds.Add( ID_FILESYSTEM_ITEMS_ENQUEUE_AFTER_ALL );
 
749
    RealAccelCmds.Add( ID_FILESYSTEM_ITEMS_ENQUEUE_AFTER_TRACK );
 
750
    RealAccelCmds.Add( ID_FILESYSTEM_ITEMS_ENQUEUE_AFTER_ALBUM );
 
751
    RealAccelCmds.Add( ID_FILESYSTEM_ITEMS_ENQUEUE_AFTER_ARTIST );
 
752
 
 
753
    if( guAccelDoAcceleratorTable( AliasAccelCmds, RealAccelCmds, AccelTable ) )
 
754
    {
 
755
        SetAcceleratorTable( AccelTable );
 
756
    }
 
757
}
 
758
 
 
759
// -------------------------------------------------------------------------------- //
 
760
wxArrayString guFilesListBox::GetColumnNames( void )
 
761
{
 
762
    wxArrayString ColumnNames;
 
763
    ColumnNames.Add( _( "Name" ) );
 
764
    ColumnNames.Add( _( "Size" ) );
 
765
    ColumnNames.Add( _( "Modified" ) );
 
766
    return ColumnNames;
 
767
}
 
768
 
 
769
// -------------------------------------------------------------------------------- //
 
770
wxString guFilesListBox::OnGetItemText( const int row, const int col ) const
 
771
{
 
772
//    guLogMessage( wxT( "GetItem: %i  %i" ), row, col );
 
773
//    if( row < 0 || col < 0 )
 
774
//        return wxEmptyString;
 
775
 
 
776
    guFileItem * FileItem;
 
777
    FileItem = &m_Files[ row ];
 
778
    switch( ( * m_Columns )[ col ].m_Id )
 
779
    {
 
780
//        case guFILEBROWSER_COLUMN_TYPE :
 
781
//            return wxEmptyString;
 
782
 
 
783
        case guFILEBROWSER_COLUMN_NAME :
 
784
          return FileItem->m_Name;
 
785
 
 
786
        case guFILEBROWSER_COLUMN_SIZE :
 
787
          return SizeToString( FileItem->m_Size );
 
788
 
 
789
        case guFILEBROWSER_COLUMN_TIME :
 
790
        {
 
791
          wxDateTime FileTime;
 
792
          FileTime.Set( ( time_t ) FileItem->m_Time );
 
793
          return FileTime.FormatDate();
 
794
        }
 
795
    }
 
796
    return wxEmptyString;
 
797
}
 
798
 
 
799
// -------------------------------------------------------------------------------- //
 
800
void guFilesListBox::DrawItem( wxDC &dc, const wxRect &rect, const int row, const int col ) const
 
801
{
 
802
    if( ( * m_Columns )[ col ].m_Id == guFILEBROWSER_COLUMN_NAME )
 
803
    {
 
804
        guFileItem * FileItem = &m_Files[ row ];
 
805
        dc.SetBackgroundMode( wxTRANSPARENT );
 
806
        int ImageIndex = guDIR_IMAGE_INDEX_OTHER;
 
807
        if( FileItem->m_Type == guFILEITEM_TYPE_FOLDER )
 
808
        {
 
809
            ImageIndex = guDIR_IMAGE_INDEX_FOLDER;
 
810
        }
 
811
        else if( FileItem->m_Type == guFILEITEM_TYPE_AUDIO )
 
812
        {
 
813
            ImageIndex = guDIR_IMAGE_INDEX_AUDIO;
 
814
        }
 
815
        else if( FileItem->m_Type == guFILEITEM_TYPE_IMAGE )
 
816
        {
 
817
            ImageIndex = guDIR_IMAGE_INDEX_IMAGE;
 
818
        }
 
819
        m_TreeImageList->Draw( ImageIndex, dc, rect.x + 1, rect.y + 1, wxIMAGELIST_DRAW_TRANSPARENT );
 
820
        wxRect TextRect = rect;
 
821
        TextRect.x += 20; // 16 + 4
 
822
        TextRect.width -= 20;
 
823
        guListView::DrawItem( dc, TextRect, row, col );
 
824
    }
 
825
    else
 
826
    {
 
827
        guListView::DrawItem( dc, rect, row, col );
 
828
    }
 
829
}
 
830
 
 
831
 
 
832
// -------------------------------------------------------------------------------- //
 
833
void inline GetFileDetails( const wxString &filename, guFileItem * fileitem )
 
834
{
 
835
    wxStructStat St;
 
836
    wxStat( filename, &St );
 
837
    fileitem->m_Type = ( ( St.st_mode & S_IFMT ) == S_IFDIR ) ? 0 : 3;
 
838
    fileitem->m_Size = St.st_size;
 
839
    fileitem->m_Time = St.st_ctime;
 
840
}
 
841
 
 
842
//// -------------------------------------------------------------------------------- //
 
843
//static int wxCMPFUNC_CONV CompareFileTypeA( guFileItem ** item1, guFileItem ** item2 )
 
844
//{
 
845
//    if( ( * item1 )->m_Name == wxT( ".." ) )
 
846
//        return -1;
 
847
//    else if( ( * item2 )->m_Name == wxT( ".." ) )
 
848
//        return 1;
 
849
//
 
850
//    if( ( * item1 )->m_Type == ( * item2 )->m_Type )
 
851
//        return 0;
 
852
//    else if( ( * item1 )->m_Type > ( * item2 )->m_Type )
 
853
//        return -1;
 
854
//    else
 
855
//        return 1;
 
856
//}
 
857
 
 
858
// -------------------------------------------------------------------------------- //
 
859
static int wxCMPFUNC_CONV CompareFileTypeD( guFileItem ** item1, guFileItem ** item2 )
 
860
{
 
861
    if( ( * item1 )->m_Name == wxT( ".." ) )
 
862
        return -1;
 
863
    else if( ( * item2 )->m_Name == wxT( ".." ) )
 
864
        return 1;
 
865
 
 
866
    if( ( * item1 )->m_Type == ( * item2 )->m_Type )
 
867
        return 0;
 
868
    else if( ( * item1 )->m_Type > ( * item2 )->m_Type )
 
869
        return 1;
 
870
    else
 
871
        return -1;
 
872
}
 
873
 
 
874
// -------------------------------------------------------------------------------- //
 
875
static int wxCMPFUNC_CONV CompareFileNameA( guFileItem ** item1, guFileItem ** item2 )
 
876
{
 
877
    int type = CompareFileTypeD( item1, item2 );
 
878
    if( !type )
 
879
        return ( * item1 )->m_Name.Cmp( ( * item2 )->m_Name );
 
880
    return type;
 
881
}
 
882
 
 
883
// -------------------------------------------------------------------------------- //
 
884
static int wxCMPFUNC_CONV CompareFileNameD( guFileItem ** item1, guFileItem ** item2 )
 
885
{
 
886
    int type = CompareFileTypeD( item1, item2 );
 
887
    if( !type )
 
888
        return ( * item2 )->m_Name.Cmp( ( * item1 )->m_Name );
 
889
    return type;
 
890
}
 
891
 
 
892
// -------------------------------------------------------------------------------- //
 
893
static int wxCMPFUNC_CONV CompareFileSizeA( guFileItem ** item1, guFileItem ** item2 )
 
894
{
 
895
    int type = CompareFileTypeD( item1, item2 );
 
896
    if( !type )
 
897
    {
 
898
        if( ( * item1 )->m_Size == ( * item2 )->m_Size )
 
899
            return 0;
 
900
        else if( ( * item1 )->m_Size > ( * item2 )->m_Size )
 
901
            return 1;
 
902
        else
 
903
            return -1;
 
904
    }
 
905
    return type;
 
906
}
 
907
 
 
908
// -------------------------------------------------------------------------------- //
 
909
static int wxCMPFUNC_CONV CompareFileSizeD( guFileItem ** item1, guFileItem ** item2 )
 
910
{
 
911
    int type = CompareFileTypeD( item1, item2 );
 
912
    if( !type )
 
913
    {
 
914
        if( ( * item1 )->m_Size == ( * item2 )->m_Size )
 
915
            return 0;
 
916
        else if( ( * item2 )->m_Size > ( * item1 )->m_Size )
 
917
            return 1;
 
918
        else
 
919
            return -1;
 
920
    }
 
921
    return type;
 
922
}
 
923
 
 
924
// -------------------------------------------------------------------------------- //
 
925
static int wxCMPFUNC_CONV CompareFileTimeA( guFileItem ** item1, guFileItem ** item2 )
 
926
{
 
927
    int type = CompareFileTypeD( item1, item2 );
 
928
    if( !type )
 
929
    {
 
930
        if( ( * item1 )->m_Time == ( * item2 )->m_Time )
 
931
            return 0;
 
932
        else if( ( * item1 )->m_Time > ( * item2 )->m_Time )
 
933
            return 1;
 
934
        else
 
935
            return -1;
 
936
    }
 
937
    return type;
 
938
}
 
939
 
 
940
// -------------------------------------------------------------------------------- //
 
941
static int wxCMPFUNC_CONV CompareFileTimeD( guFileItem ** item1, guFileItem ** item2 )
 
942
{
 
943
    int type = CompareFileTypeD( item1, item2 );
 
944
    if( !type )
 
945
    {
 
946
        if( ( * item1 )->m_Time == ( * item2 )->m_Time )
 
947
            return 0;
 
948
        else if( ( * item2 )->m_Time > ( * item1 )->m_Time )
 
949
            return 1;
 
950
        else
 
951
            return -1;
 
952
    }
 
953
    return type;
 
954
}
 
955
 
 
956
// -------------------------------------------------------------------------------- //
 
957
int guFilesListBox::GetPathSordedItems( const wxString &path, guFileItemArray * items,
 
958
    const int order, const bool orderdesc, const bool recursive ) const
 
959
{
 
960
    wxString Path = path;
 
961
    if( !Path.EndsWith( wxT( "/" ) ) )
 
962
        Path += wxT( "/" );
 
963
    if( !path.IsEmpty() && wxDirExists( Path ) )
 
964
    {
 
965
        wxDir Dir( Path );
 
966
        if( Dir.IsOpened() )
 
967
        {
 
968
            wxString FileName;
 
969
            if( Dir.GetFirst( &FileName, wxEmptyString, wxDIR_FILES | wxDIR_DIRS | wxDIR_DOTDOT ) )
 
970
            {
 
971
                do {
 
972
                    if( FileName != wxT( "." ) )
 
973
                    {
 
974
                        if( recursive && wxDirExists( Path + FileName ) )
 
975
                        {
 
976
                            if( FileName != wxT( ".." ) )
 
977
                            {
 
978
                                GetPathSordedItems( Path + FileName, items, order, orderdesc, recursive );
 
979
                            }
 
980
                        }
 
981
                        else
 
982
                        {
 
983
                            guFileItem * FileItem = new guFileItem();
 
984
                            if( recursive )
 
985
                                FileItem->m_Name = Path;
 
986
                            FileItem->m_Name += FileName;
 
987
                            GetFileDetails( Path + FileName, FileItem );
 
988
                            if( !wxDirExists( Path + FileName ) )
 
989
                            {
 
990
                                if( guIsValidAudioFile( FileName.Lower() ) )
 
991
                                    FileItem->m_Type = guFILEITEM_TYPE_AUDIO;
 
992
                                else if( guIsValidImageFile( FileName.Lower() ) )
 
993
                                    FileItem->m_Type = guFILEITEM_TYPE_IMAGE;
 
994
                            }
 
995
                            items->Add( FileItem );
 
996
                        }
 
997
                    }
 
998
                } while( Dir.GetNext( &FileName ) );
 
999
            }
 
1000
 
 
1001
            switch( order )
 
1002
            {
 
1003
                case guFILEBROWSER_COLUMN_NAME :
 
1004
                {
 
1005
                    items->Sort( orderdesc ? CompareFileNameD : CompareFileNameA );
 
1006
                    break;
 
1007
                }
 
1008
 
 
1009
                case guFILEBROWSER_COLUMN_SIZE :
 
1010
                {
 
1011
                    items->Sort( orderdesc ? CompareFileSizeD : CompareFileSizeA );
 
1012
                    break;
 
1013
                }
 
1014
 
 
1015
                case guFILEBROWSER_COLUMN_TIME :
 
1016
                {
 
1017
                    items->Sort( orderdesc ? CompareFileTimeD : CompareFileTimeA );
 
1018
                    break;
 
1019
                }
 
1020
            }
 
1021
        }
 
1022
    }
 
1023
    return items->Count();
 
1024
}
 
1025
 
 
1026
// -------------------------------------------------------------------------------- //
 
1027
void guFilesListBox::GetItemsList( void )
 
1028
{
 
1029
    GetPathSordedItems( m_CurDir, &m_Files, m_Order, m_OrderDesc );
 
1030
 
 
1031
    wxCommandEvent event( wxEVT_COMMAND_MENU_SELECTED, ID_MAINFRAME_UPDATE_SELINFO );
 
1032
    AddPendingEvent( event );
 
1033
}
 
1034
 
 
1035
// -------------------------------------------------------------------------------- //
 
1036
void guFilesListBox::ReloadItems( bool reset )
 
1037
{
 
1038
    //
 
1039
    wxArrayInt Selection;
 
1040
    int FirstVisible = 0;
 
1041
 
 
1042
    if( reset )
 
1043
    {
 
1044
        SetSelection( -1 );
 
1045
    }
 
1046
    else
 
1047
    {
 
1048
        Selection = GetSelectedItems( false );
 
1049
        FirstVisible = GetFirstVisibleLine();
 
1050
    }
 
1051
 
 
1052
    m_Files.Empty();
 
1053
 
 
1054
    GetItemsList();
 
1055
 
 
1056
    SetItemCount( m_Files.Count() );
 
1057
 
 
1058
    if( !reset )
 
1059
    {
 
1060
      SetSelectedItems( Selection );
 
1061
      ScrollToLine( FirstVisible );
 
1062
    }
 
1063
    RefreshAll();
 
1064
}
 
1065
 
 
1066
// -------------------------------------------------------------------------------- //
 
1067
void AppendItemsCommands( wxMenu * menu, int selcount, int seltype )
 
1068
{
 
1069
    wxMenu * SubMenu;
 
1070
    int Index;
 
1071
    int Count;
 
1072
    wxMenuItem * MenuItem;
 
1073
 
 
1074
    SubMenu = new wxMenu();
 
1075
 
 
1076
    guLogMessage( wxT( "AppendItemCommands: %i  %i" ), selcount, seltype );
 
1077
 
 
1078
    guConfig * Config = ( guConfig * ) guConfig::Get();
 
1079
    wxArrayString Commands = Config->ReadAStr( wxT( "Exec" ), wxEmptyString, wxT( "commands/execs" ) );
 
1080
    wxArrayString Names = Config->ReadAStr( wxT( "Name" ), wxEmptyString, wxT( "commands/names" ) );
 
1081
    if( ( Count = Commands.Count() ) )
 
1082
    {
 
1083
        for( Index = 0; Index < Count; Index++ )
 
1084
        {
 
1085
            if( ( Commands[ Index ].Find( wxT( "{bc}" ) ) == wxNOT_FOUND ) ||
 
1086
                ( ( selcount == 1 ) && ( seltype == guFILEITEM_TYPE_IMAGE ) ) )
 
1087
            {
 
1088
                MenuItem = new wxMenuItem( menu, ID_COMMANDS_BASE + Index, Names[ Index ], Commands[ Index ] );
 
1089
                SubMenu->Append( MenuItem );
 
1090
            }
 
1091
        }
 
1092
 
 
1093
        SubMenu->AppendSeparator();
 
1094
    }
 
1095
    else
 
1096
    {
 
1097
        MenuItem = new wxMenuItem( SubMenu, ID_MENU_PREFERENCES_COMMANDS, _( "Preferences" ), _( "Add commands in preferences" ) );
 
1098
        SubMenu->Append( MenuItem );
 
1099
    }
 
1100
    menu->AppendSubMenu( SubMenu, _( "Commands" ) );
 
1101
}
 
1102
 
 
1103
// -------------------------------------------------------------------------------- //
 
1104
void guFilesListBox::CreateContextMenu( wxMenu * Menu ) const
 
1105
{
 
1106
    wxMenuItem * MenuItem;
 
1107
    wxArrayInt Selection = GetSelectedItems( false );
 
1108
    int SelCount;
 
1109
    if( ( SelCount = Selection.Count() ) )
 
1110
    {
 
1111
        MenuItem = new wxMenuItem( Menu, ID_FILESYSTEM_ITEMS_PLAY,
 
1112
                            wxString( _( "Play" ) ) + guAccelGetCommandKeyCodeString( ID_TRACKS_PLAY ),
 
1113
                            _( "Play current selected files" ) );
 
1114
        MenuItem->SetBitmap( guImage( guIMAGE_INDEX_player_tiny_light_play ) );
 
1115
        Menu->Append( MenuItem );
 
1116
 
 
1117
        MenuItem = new wxMenuItem( Menu, ID_FILESYSTEM_ITEMS_ENQUEUE_AFTER_ALL,
 
1118
                            wxString( _( "Enqueue" ) ) + guAccelGetCommandKeyCodeString( ID_TRACKS_ENQUEUE_AFTER_ALL ),
 
1119
                            _( "Add current selected files to playlist" ) );
 
1120
        MenuItem->SetBitmap( guImage( guIMAGE_INDEX_tiny_add ) );
 
1121
        Menu->Append( MenuItem );
 
1122
 
 
1123
        wxMenu * EnqueueMenu = new wxMenu();
 
1124
 
 
1125
        MenuItem = new wxMenuItem( EnqueueMenu, ID_FILESYSTEM_ITEMS_ENQUEUE_AFTER_TRACK,
 
1126
                                wxString( _( "Current Track" ) ) +  guAccelGetCommandKeyCodeString( ID_TRACKS_ENQUEUE_AFTER_TRACK ),
 
1127
                                _( "Add current selected tracks to playlist after the current track" ) );
 
1128
        MenuItem->SetBitmap( guImage( guIMAGE_INDEX_tiny_add ) );
 
1129
        EnqueueMenu->Append( MenuItem );
 
1130
        MenuItem->Enable( SelCount );
 
1131
 
 
1132
        MenuItem = new wxMenuItem( EnqueueMenu, ID_FILESYSTEM_ITEMS_ENQUEUE_AFTER_ALBUM,
 
1133
                                wxString( _( "Current Album" ) ) +  guAccelGetCommandKeyCodeString( ID_TRACKS_ENQUEUE_AFTER_ALBUM ),
 
1134
                                _( "Add current selected tracks to playlist after the current album" ) );
 
1135
        MenuItem->SetBitmap( guImage( guIMAGE_INDEX_tiny_add ) );
 
1136
        EnqueueMenu->Append( MenuItem );
 
1137
        MenuItem->Enable( SelCount );
 
1138
 
 
1139
        MenuItem = new wxMenuItem( EnqueueMenu, ID_FILESYSTEM_ITEMS_ENQUEUE_AFTER_ARTIST,
 
1140
                                wxString( _( "Current Artist" ) ) +  guAccelGetCommandKeyCodeString( ID_TRACKS_ENQUEUE_AFTER_ARTIST ),
 
1141
                                _( "Add current selected tracks to playlist after the current artist" ) );
 
1142
        MenuItem->SetBitmap( guImage( guIMAGE_INDEX_tiny_add ) );
 
1143
        EnqueueMenu->Append( MenuItem );
 
1144
        MenuItem->Enable( SelCount );
 
1145
 
 
1146
        Menu->Append( wxID_ANY, _( "Enqueue After" ), EnqueueMenu );
 
1147
    }
 
1148
 
 
1149
    if( SelCount )
 
1150
    {
 
1151
        Menu->AppendSeparator();
 
1152
 
 
1153
        MenuItem = new wxMenuItem( Menu, ID_FILESYSTEM_ITEMS_EDITTRACKS,
 
1154
                            wxString( _( "Edit Tracks" ) ) + guAccelGetCommandKeyCodeString( ID_PLAYER_PLAYLIST_EDITTRACKS ),
 
1155
                            _( "Edit the current selected files" ) );
 
1156
        MenuItem->SetBitmap( guImage( guIMAGE_INDEX_tiny_edit ) );
 
1157
        Menu->Append( MenuItem );
 
1158
 
 
1159
        Menu->AppendSeparator();
 
1160
 
 
1161
        MenuItem = new wxMenuItem( Menu, ID_FILESYSTEM_ITEMS_SAVEPLAYLIST,
 
1162
                            wxString( _( "Save to Playlist" ) ) + guAccelGetCommandKeyCodeString( ID_PLAYER_PLAYLIST_SAVE ),
 
1163
                            _( "Add the current selected tracks to a playlist" ) );
 
1164
        MenuItem->SetBitmap( guImage( guIMAGE_INDEX_tiny_doc_save ) );
 
1165
        Menu->Append( MenuItem );
 
1166
    }
 
1167
 
 
1168
    Menu->AppendSeparator();
 
1169
 
 
1170
    MenuItem = new wxMenuItem( Menu, ID_FILESYSTEM_ITEMS_COPY, _( "Copy" ), _( "Copy the selected folder to clipboard" ) );
 
1171
    MenuItem->SetBitmap( guImage( guIMAGE_INDEX_tiny_edit_copy ) );
 
1172
    Menu->Append( MenuItem );
 
1173
 
 
1174
    MenuItem = new wxMenuItem( Menu, ID_FILESYSTEM_ITEMS_PASTE, _( "Paste" ), _( "Paste to the selected dir" ) );
 
1175
    Menu->Append( MenuItem );
 
1176
    wxTheClipboard->UsePrimarySelection( false );
 
1177
    if( wxTheClipboard->Open() )
 
1178
    {
 
1179
        if( wxTheClipboard->IsSupported( wxDF_FILENAME ) )
 
1180
        {
 
1181
            wxFileDataObject data;
 
1182
            MenuItem->Enable( wxTheClipboard->GetData( data ) );
 
1183
        }
 
1184
        wxTheClipboard->Close();
 
1185
    }
 
1186
 
 
1187
    if( SelCount )
 
1188
    {
 
1189
        Menu->AppendSeparator();
 
1190
 
 
1191
        MenuItem = new wxMenuItem( Menu, ID_FILESYSTEM_ITEMS_RENAME, _( "Rename Files" ), _( "Rename the current selected file" ) );
 
1192
        MenuItem->SetBitmap( guImage( guIMAGE_INDEX_tiny_edit ) );
 
1193
        Menu->Append( MenuItem );
 
1194
 
 
1195
        MenuItem = new wxMenuItem( Menu, ID_FILESYSTEM_ITEMS_DELETE, _( "Remove" ), _( "Delete the selected files" ) );
 
1196
        MenuItem->SetBitmap( guImage( guIMAGE_INDEX_tiny_edit_clear ) );
 
1197
        Menu->Append( MenuItem );
 
1198
 
 
1199
        Menu->AppendSeparator();
 
1200
 
 
1201
        guMainFrame * MainFrame = ( guMainFrame * ) wxTheApp->GetTopWindow();
 
1202
        MainFrame->CreateCopyToMenu( Menu );
 
1203
 
 
1204
        AppendItemsCommands( Menu, SelCount, SelCount ? GetType( Selection[ 0 ] ) : guFILEITEM_TYPE_FILE );
 
1205
    }
 
1206
}
 
1207
 
 
1208
// -------------------------------------------------------------------------------- //
 
1209
int inline guFilesListBox::GetItemId( const int row ) const
 
1210
{
 
1211
    return row;
 
1212
}
 
1213
 
 
1214
// -------------------------------------------------------------------------------- //
 
1215
wxString inline guFilesListBox::GetItemName( const int row ) const
 
1216
{
 
1217
    return m_Files[ row ].m_Name;
 
1218
}
 
1219
 
 
1220
// -------------------------------------------------------------------------------- //
 
1221
void guFilesListBox::SetOrder( int columnid )
 
1222
{
 
1223
    if( m_Order != columnid )
 
1224
    {
 
1225
        m_Order = columnid;
 
1226
        m_OrderDesc = ( columnid != 0 );
 
1227
    }
 
1228
    else
 
1229
        m_OrderDesc = !m_OrderDesc;
 
1230
 
 
1231
    wxArrayString ColumnNames = GetColumnNames();
 
1232
    int CurColId;
 
1233
    int index;
 
1234
    int count = ColumnNames.Count();
 
1235
    for( index = 0; index < count; index++ )
 
1236
    {
 
1237
        CurColId = GetColumnId( index );
 
1238
        SetColumnLabel( index,
 
1239
            ColumnNames[ CurColId ]  + ( ( CurColId == m_Order ) ?
 
1240
                ( m_OrderDesc ? wxT( " ▼" ) : wxT( " ▲" ) ) : wxEmptyString ) );
 
1241
    }
 
1242
 
 
1243
    ReloadItems();
 
1244
}
 
1245
 
 
1246
// -------------------------------------------------------------------------------- //
 
1247
int guFilesListBox::GetSelectedSongs( guTrackArray * tracks, const bool isdrag ) const
 
1248
{
 
1249
    wxArrayString Files = GetSelectedFiles( true );
 
1250
    return GetTracksFromFiles( Files, tracks );
 
1251
}
 
1252
 
 
1253
// -------------------------------------------------------------------------------- //
 
1254
int guFilesListBox::GetAllSongs( guTrackArray * tracks ) const
 
1255
{
 
1256
    wxArrayString Files = GetAllFiles( true );
 
1257
    return GetTracksFromFiles( Files, tracks );
 
1258
}
 
1259
 
 
1260
// -------------------------------------------------------------------------------- //
 
1261
int guFilesListBox::GetTracksFromFiles( const wxArrayString &files, guTrackArray * tracks ) const
 
1262
{
 
1263
    int Index;
 
1264
    int Count;
 
1265
    if( ( Count = files.Count() ) )
 
1266
    {
 
1267
        for( Index = 0; Index < Count; Index++ )
 
1268
        {
 
1269
            wxString FileName = files[ Index ];
 
1270
            //guLogMessage( wxT( "GetTracksFromFiles: %s" ), FileName.c_str() );
 
1271
            wxURI Uri( FileName );
 
1272
 
 
1273
            if( Uri.IsReference() )
 
1274
            {
 
1275
                if( guIsValidAudioFile( FileName ) )
 
1276
                {
 
1277
                    guTrack * Track = new guTrack();
 
1278
                    Track->m_FileName = FileName;
 
1279
 
 
1280
                    if( !m_Db || !m_Db->FindTrackFile( FileName, Track ) )
 
1281
                    {
 
1282
                        guPodcastItem PodcastItem;
 
1283
                        guMainFrame * MainFrame = ( guMainFrame * ) wxTheApp->GetTopWindow();
 
1284
                        guDbPodcasts * DbPodcasts = MainFrame->GetPodcastsDb();
 
1285
                        if( DbPodcasts->GetPodcastItemFile( FileName, &PodcastItem ) )
 
1286
                        {
 
1287
                            delete Track;
 
1288
                            continue;
 
1289
                        }
 
1290
                        else
 
1291
                        {
 
1292
                            if( Track->ReadFromFile( FileName ) )
 
1293
                            {
 
1294
                                Track->m_Type = guTRACK_TYPE_NOTDB;
 
1295
                            }
 
1296
                            else
 
1297
                            {
 
1298
                                guLogError( wxT( "Could not read tags from file '%s'" ), FileName.c_str() );
 
1299
                            }
 
1300
                        }
 
1301
                    }
 
1302
 
 
1303
                    tracks->Add( Track );
 
1304
                }
 
1305
            }
 
1306
        }
 
1307
    }
 
1308
    return tracks->Count();
 
1309
}
 
1310
 
 
1311
// -------------------------------------------------------------------------------- //
 
1312
wxArrayString guFilesListBox::GetSelectedFiles( const bool recursive ) const
 
1313
{
 
1314
    wxArrayString Files;
 
1315
    wxArrayInt Selection = GetSelectedItems( false );
 
1316
    int Index;
 
1317
    int Count;
 
1318
    if( ( Count = Selection.Count() ) )
 
1319
    {
 
1320
        for( Index = 0; Index < Count; Index++ )
 
1321
        {
 
1322
            if( m_Files[ Selection[ Index ] ].m_Name != wxT( ".." ) )
 
1323
            {
 
1324
                if( recursive && ( m_Files[ Selection[ Index ] ].m_Type == guFILEITEM_TYPE_FOLDER ) )
 
1325
                {
 
1326
                    //guAddDirItems( m_CurDir + m_Files[ Selection[ Index ] ].m_Name, Files );
 
1327
                    guFileItemArray DirFiles;
 
1328
                    if( GetPathSordedItems( m_CurDir + m_Files[ Selection[ Index ] ].m_Name,
 
1329
                                            &DirFiles, m_Order, m_OrderDesc, true ) )
 
1330
                    {
 
1331
                        int FileIndex;
 
1332
                        int FileCount = DirFiles.Count();
 
1333
                        for( FileIndex = 0; FileIndex < FileCount; FileIndex++ )
 
1334
                        {
 
1335
                            Files.Add( DirFiles[ FileIndex ].m_Name );
 
1336
                        }
 
1337
                    }
 
1338
                }
 
1339
                else
 
1340
                {
 
1341
                    Files.Add( m_CurDir + m_Files[ Selection[ Index ] ].m_Name );
 
1342
                }
 
1343
            }
 
1344
        }
 
1345
    }
 
1346
    return Files;
 
1347
}
 
1348
 
 
1349
// -------------------------------------------------------------------------------- //
 
1350
wxArrayString guFilesListBox::GetAllFiles( const bool recursive ) const
 
1351
{
 
1352
    wxArrayString Files;
 
1353
    int Index;
 
1354
    int Count = m_Files.Count();
 
1355
    if( Count )
 
1356
    {
 
1357
        for( Index = 0; Index < Count; Index++ )
 
1358
        {
 
1359
            if( m_Files[ Index ].m_Name != wxT( ".." ) )
 
1360
            {
 
1361
                if( recursive && ( m_Files[ Index ].m_Type == guFILEITEM_TYPE_FOLDER ) )
 
1362
                {
 
1363
                    //guAddDirItems( m_CurDir + m_Files[ Selection[ Index ] ].m_Name, Files );
 
1364
                    guFileItemArray DirFiles;
 
1365
                    if( GetPathSordedItems( m_CurDir + m_Files[ Index ].m_Name,
 
1366
                                            &DirFiles, m_Order, m_OrderDesc, true ) )
 
1367
                    {
 
1368
                        int FileIndex;
 
1369
                        int FileCount = DirFiles.Count();
 
1370
                        for( FileIndex = 0; FileIndex < FileCount; FileIndex++ )
 
1371
                        {
 
1372
                            Files.Add( DirFiles[ FileIndex ].m_Name );
 
1373
                        }
 
1374
                    }
 
1375
                }
 
1376
                else
 
1377
                {
 
1378
                    Files.Add( m_CurDir + m_Files[ Index ].m_Name );
 
1379
                }
 
1380
            }
 
1381
        }
 
1382
    }
 
1383
    return Files;
 
1384
}
 
1385
 
 
1386
// -------------------------------------------------------------------------------- //
 
1387
int guFilesListBox::GetDragFiles( guDataObjectComposite * files )
 
1388
{
 
1389
    wxArrayString SelectFiles = GetSelectedFiles( true );
 
1390
    int Index;
 
1391
    int Count = SelectFiles.Count();
 
1392
    for( Index = 0; Index < Count; Index++ )
 
1393
    {
 
1394
       SelectFiles[ Index ] = guFileDnDEncode( SelectFiles[ Index ] );
 
1395
    }
 
1396
    files->SetFiles( SelectFiles );
 
1397
    return Count;
 
1398
}
 
1399
 
 
1400
// -------------------------------------------------------------------------------- //
 
1401
void guFilesListBox::SetPath( const wxString &path, guMediaViewer * mediaviewer )
 
1402
{
 
1403
    guLogMessage( wxT( "guFilesListBox::SetPath( %s )" ), path.c_str() );
 
1404
    m_CurDir = path;
 
1405
    if( !m_CurDir.EndsWith( wxT( "/" ) ) )
 
1406
        m_CurDir += wxT( "/" );
 
1407
    m_MediaViewer = mediaviewer;
 
1408
    m_Db = mediaviewer ? mediaviewer->GetDb() : NULL;
 
1409
    ReloadItems();
 
1410
}
 
1411
 
 
1412
// -------------------------------------------------------------------------------- //
 
1413
wxString guFilesListBox::GetPath( const int item, const bool absolute ) const
 
1414
{
 
1415
    wxString RetVal;
 
1416
    //guLogMessage( wxT( "GetPath( %i )" ), item );
 
1417
    if( item >= 0 )
 
1418
    {
 
1419
        if( !absolute )
 
1420
        {
 
1421
            return m_CurDir + m_Files[ item ].m_Name;
 
1422
        }
 
1423
        else
 
1424
        {
 
1425
            if( m_Files[ item ].m_Name == wxT( ".." ) )
 
1426
            {
 
1427
                RetVal = m_CurDir.BeforeLast( wxT( '/' ) ).BeforeLast( wxT( '/' ) );
 
1428
                //guLogMessage( wxT( "1) Path : %s" ), RetVal.c_str() );
 
1429
                return RetVal;
 
1430
            }
 
1431
 
 
1432
            wxFileName FileName( m_Files[ item ].m_Name );
 
1433
            FileName.MakeAbsolute( m_CurDir );
 
1434
            //guLogMessage( wxT( "Path : %s" ), FileName.GetFullPath().c_str() );
 
1435
            return FileName.GetFullPath();
 
1436
        }
 
1437
    }
 
1438
    return wxEmptyString;
 
1439
}
 
1440
 
 
1441
// -------------------------------------------------------------------------------- //
 
1442
int guFilesListBox::GetType( const int item ) const
 
1443
{
 
1444
    if( item >= 0 )
 
1445
    {
 
1446
        return m_Files[ item ].m_Type;
 
1447
    }
 
1448
    return wxNOT_FOUND;
 
1449
}
 
1450
 
 
1451
// -------------------------------------------------------------------------------- //
 
1452
bool guFilesListBox::GetCounters( wxLongLong * count, wxLongLong * len, wxLongLong * size )
 
1453
{
 
1454
    int Index;
 
1455
    int Count;
 
1456
    * count = * len = * size = 0;
 
1457
    Count = m_Files.Count();
 
1458
    for( Index = 0; Index < Count; Index++ )
 
1459
    {
 
1460
        if( m_Files[ Index ].m_Type == guFILEITEM_TYPE_FOLDER )
 
1461
        {
 
1462
            if( ( m_Files[ Index ].m_Name != wxT( ".." ) ) )
 
1463
                ( * len )++;
 
1464
        }
 
1465
        else
 
1466
        {
 
1467
            * size += m_Files[ Index ].m_Size;
 
1468
            ( * count )++;
 
1469
        }
 
1470
    }
 
1471
    return true;
 
1472
}
 
1473
 
 
1474
 
 
1475
// -------------------------------------------------------------------------------- //
 
1476
// guFileBrowserFileCtrl
 
1477
// -------------------------------------------------------------------------------- //
 
1478
guFileBrowserFileCtrl::guFileBrowserFileCtrl( wxWindow * parent, guDbLibrary * db, guFileBrowserDirCtrl * dirctrl ) :
 
1479
    wxPanel( parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL|wxNO_BORDER )
 
1480
{
 
1481
    m_DefaultDb = db;
 
1482
    m_Db = NULL;
 
1483
    m_MediaViewer = NULL;
 
1484
    m_DirCtrl = dirctrl;
 
1485
    wxImageList * ImageList = dirctrl->GetImageList();
 
1486
    ImageList->Add( wxArtProvider::GetBitmap( wxT( "audio-x-generic" ), wxART_OTHER, wxSize( 16, 16 ) ) );
 
1487
    ImageList->Add( wxArtProvider::GetBitmap( wxT( "image-x-generic" ), wxART_OTHER, wxSize( 16, 16 ) ) );
 
1488
 
 
1489
        wxBoxSizer * MainSizer;
 
1490
        MainSizer = new wxBoxSizer( wxVERTICAL );
 
1491
 
 
1492
        m_FilesListBox = new guFilesListBox( this, db );
 
1493
        m_FilesListBox->SetTreeImageList( ImageList );
 
1494
        MainSizer->Add( m_FilesListBox, 1, wxEXPAND, 5 );
 
1495
 
 
1496
        this->SetSizer( MainSizer );
 
1497
        this->Layout();
 
1498
 
 
1499
}
 
1500
 
 
1501
// -------------------------------------------------------------------------------- //
 
1502
guFileBrowserFileCtrl::~guFileBrowserFileCtrl()
 
1503
{
 
1504
}
 
1505
 
 
1506
// -------------------------------------------------------------------------------- //
 
1507
void guFileBrowserFileCtrl::SetPath( const wxString &path, guMediaViewer * mediaviewer )
 
1508
{
 
1509
    guLogMessage( wxT( "guFileBrowserFileCtrl::SetPath( %s )" ), path.c_str() );
 
1510
    m_MediaViewer = mediaviewer;
 
1511
    m_Db = mediaviewer ? mediaviewer->GetDb() : NULL;
 
1512
    m_FilesListBox->SetPath( path, mediaviewer );
 
1513
}
 
1514
 
 
1515
 
 
1516
 
 
1517
// -------------------------------------------------------------------------------- //
 
1518
// guFileBrowser
 
1519
// -------------------------------------------------------------------------------- //
 
1520
BEGIN_EVENT_TABLE( guFileBrowser, wxPanel )
 
1521
    EVT_TREE_BEGIN_DRAG( wxID_ANY, guFileBrowser::OnDirBeginDrag)
 
1522
END_EVENT_TABLE()
 
1523
 
 
1524
// -------------------------------------------------------------------------------- //
 
1525
guFileBrowser::guFileBrowser( wxWindow * parent, guMainFrame * mainframe, guDbLibrary * db, guPlayerPanel * playerpanel ) :
 
1526
    guAuiManagerPanel( parent )
 
1527
{
 
1528
    m_MainFrame = mainframe;
 
1529
    m_DefaultDb = db;
 
1530
    m_Db = NULL;
 
1531
    m_MediaViewer = NULL;
 
1532
    m_PlayerPanel = playerpanel;
 
1533
 
 
1534
    guConfig *  Config = ( guConfig * ) guConfig::Get();
 
1535
 
 
1536
    m_VisiblePanels = Config->ReadNum( wxT( "VisiblePanels" ), guPANEL_FILEBROWSER_VISIBLE_DEFAULT, wxT( "filebrowser" ) );
 
1537
 
 
1538
 
 
1539
    wxString LastPath = Config->ReadStr( wxT( "Path" ), wxEmptyString, wxT( "filebrowser" ) );
 
1540
    m_DirCtrl = new guFileBrowserDirCtrl( this, m_MainFrame, db, LastPath );
 
1541
    guLogMessage( wxT( "LastPath: '%s'" ), LastPath.c_str() );
 
1542
 
 
1543
    m_AuiManager.AddPane( m_DirCtrl,
 
1544
            wxAuiPaneInfo().Name( wxT( "FileBrowserDirCtrl" ) ).Caption( _( "Directories" ) ).
 
1545
            MinSize( 60, 28 ).Row( 0 ).Layer( 0 ).Position( 0 ).
 
1546
            CloseButton( false ).
 
1547
            Dockable( true ).Left() );
 
1548
 
 
1549
    m_FilesCtrl = new guFileBrowserFileCtrl( this, db, m_DirCtrl );
 
1550
    m_FilesCtrl->SetPath( LastPath, NULL );
 
1551
 
 
1552
    m_AuiManager.AddPane( m_FilesCtrl,
 
1553
            wxAuiPaneInfo().Name( wxT( "FileBrowserFilesCtrl" ) ).
 
1554
            Dockable( true ).CenterPane() );
 
1555
 
 
1556
    wxString FileBrowserLayout = Config->ReadStr( wxT( "LastLayout" ), wxEmptyString, wxT( "filebrowser" ) );
 
1557
    if( Config->GetIgnoreLayouts() || FileBrowserLayout.IsEmpty() )
 
1558
    {
 
1559
        m_VisiblePanels = guPANEL_FILEBROWSER_VISIBLE_DEFAULT;
 
1560
        FileBrowserLayout = wxT( "layout2|name=FileBrowserDirCtrl;caption=" ) + wxString( _( "Directories" ) );
 
1561
        FileBrowserLayout += wxT( ";state=2044;dir=4;layer=0;row=0;pos=0;prop=100000;bestw=60;besth=28;minw=60;minh=28;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|" );
 
1562
        FileBrowserLayout += wxT( "name=FileBrowserFilesCtrl;caption=;state=768;dir=5;layer=0;row=0;pos=0;prop=100000;bestw=20;besth=20;minw=-1;minh=-1;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1| " );
 
1563
        FileBrowserLayout += wxT( "dock_size(5,0,0)=10|dock_size(4,0,0)=266|" );
 
1564
        //m_AuiManager.Update();
 
1565
    }
 
1566
 
 
1567
    m_AuiManager.LoadPerspective( FileBrowserLayout, true );
 
1568
 
 
1569
        m_DirCtrl->Connect( wxEVT_COMMAND_TREE_SEL_CHANGED, wxTreeEventHandler( guFileBrowser::OnDirItemChanged ), NULL, this );
 
1570
    m_FilesCtrl->Connect( wxEVT_COMMAND_LISTBOX_DOUBLECLICKED,  wxListEventHandler( guFileBrowser::OnFileItemActivated ), NULL, this );
 
1571
        m_FilesCtrl->Connect( wxEVT_COMMAND_LIST_COL_CLICK, wxListEventHandler( guFileBrowser::OnFilesColClick ), NULL, this );
 
1572
 
 
1573
    Connect( ID_FILESYSTEM_FOLDER_PLAY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnFolderPlay ), NULL, this );
 
1574
    Connect( ID_FILESYSTEM_FOLDER_ENQUEUE_AFTER_ALL, ID_FILESYSTEM_FOLDER_ENQUEUE_AFTER_ARTIST, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnFolderEnqueue ), NULL, this );
 
1575
    Connect( ID_FILESYSTEM_FOLDER_NEW, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnFolderNew ), NULL, this );
 
1576
    Connect( ID_FILESYSTEM_FOLDER_RENAME, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnFolderRename ), NULL, this );
 
1577
    Connect( ID_FILESYSTEM_FOLDER_DELETE, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnFolderDelete ), NULL, this );
 
1578
    Connect( ID_FILESYSTEM_FOLDER_COPY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnFolderCopy ), NULL, this );
 
1579
    Connect( ID_FILESYSTEM_FOLDER_PASTE, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnFolderPaste ), NULL, this );
 
1580
    Connect( ID_FILESYSTEM_FOLDER_EDITTRACKS, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnFolderEditTracks ), NULL, this );
 
1581
    Connect( ID_FILESYSTEM_FOLDER_SAVEPLAYLIST, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnFolderSaveToPlayList ), NULL, this );
 
1582
    m_DirCtrl->Connect( ID_COPYTO_BASE, ID_COPYTO_BASE + guCOPYTO_MAXCOUNT, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnFolderCopyTo ), NULL, this );
 
1583
 
 
1584
    m_DirCtrl->Connect( ID_COMMANDS_BASE, ID_COMMANDS_BASE + guCOMMANDS_MAXCOUNT, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnFolderCommand ), NULL, this );
 
1585
 
 
1586
    Connect( ID_FILESYSTEM_ITEMS_PLAY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnItemsPlay ), NULL, this );
 
1587
    Connect( ID_FILESYSTEM_ITEMS_ENQUEUE_AFTER_ALL, ID_FILESYSTEM_ITEMS_ENQUEUE_AFTER_ARTIST, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnItemsEnqueue ), NULL, this );
 
1588
    Connect( ID_FILESYSTEM_ITEMS_EDITTRACKS, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnItemsEditTracks ), NULL, this );
 
1589
    Connect( ID_FILESYSTEM_ITEMS_SAVEPLAYLIST, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnItemsSaveToPlayList ), NULL, this );
 
1590
    m_FilesCtrl->Connect( ID_COPYTO_BASE, ID_COPYTO_BASE + guCOPYTO_MAXCOUNT, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnItemsCopyTo ), NULL, this );
 
1591
    Connect( ID_FILESYSTEM_ITEMS_RENAME, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnItemsRename ), NULL, this );
 
1592
    Connect( ID_FILESYSTEM_ITEMS_DELETE, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnItemsDelete ), NULL, this );
 
1593
    Connect( ID_FILESYSTEM_ITEMS_COPY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnItemsCopy ), NULL, this );
 
1594
    Connect( ID_FILESYSTEM_ITEMS_PASTE, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnItemsPaste ), NULL, this );
 
1595
 
 
1596
    m_FilesCtrl->Connect( ID_COMMANDS_BASE, ID_COMMANDS_BASE + guCOMMANDS_MAXCOUNT, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnItemsCommand ), NULL, this );
 
1597
}
 
1598
 
 
1599
// -------------------------------------------------------------------------------- //
 
1600
guFileBrowser::~guFileBrowser()
 
1601
{
 
1602
    guConfig *  Config = ( guConfig * ) guConfig::Get();
 
1603
    Config->WriteNum( wxT( "VisiblePanels" ), m_VisiblePanels, wxT( "filebrowser" ) );
 
1604
    Config->WriteStr( wxT( "LastLayout" ), m_AuiManager.SavePerspective(), wxT( "filebrowser" ) );
 
1605
    Config->WriteStr( wxT( "Path" ), m_DirCtrl->GetPath(), wxT( "filebrowser" ) );
 
1606
 
 
1607
        m_DirCtrl->Disconnect( wxEVT_COMMAND_TREE_SEL_CHANGED, wxTreeEventHandler( guFileBrowser::OnDirItemChanged ), NULL, this );
 
1608
    m_FilesCtrl->Disconnect( wxEVT_COMMAND_LISTBOX_DOUBLECLICKED,  wxListEventHandler( guFileBrowser::OnFileItemActivated ), NULL, this );
 
1609
        m_FilesCtrl->Disconnect( wxEVT_COMMAND_LIST_COL_CLICK, wxListEventHandler( guFileBrowser::OnFilesColClick ), NULL, this );
 
1610
 
 
1611
    Disconnect( ID_FILESYSTEM_FOLDER_PLAY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnFolderPlay ), NULL, this );
 
1612
    Disconnect( ID_FILESYSTEM_FOLDER_ENQUEUE_AFTER_ALL, ID_FILESYSTEM_FOLDER_ENQUEUE_AFTER_ARTIST, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnFolderEnqueue ), NULL, this );
 
1613
    Disconnect( ID_FILESYSTEM_FOLDER_NEW, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnFolderNew ), NULL, this );
 
1614
    Disconnect( ID_FILESYSTEM_FOLDER_RENAME, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnFolderRename ), NULL, this );
 
1615
    Disconnect( ID_FILESYSTEM_FOLDER_DELETE, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnFolderDelete ), NULL, this );
 
1616
    Disconnect( ID_FILESYSTEM_FOLDER_COPY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnFolderCopy ), NULL, this );
 
1617
    Disconnect( ID_FILESYSTEM_FOLDER_PASTE, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnFolderPaste ), NULL, this );
 
1618
    Disconnect( ID_FILESYSTEM_FOLDER_EDITTRACKS, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnFolderEditTracks ), NULL, this );
 
1619
    Disconnect( ID_FILESYSTEM_FOLDER_SAVEPLAYLIST, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnFolderSaveToPlayList ), NULL, this );
 
1620
    m_DirCtrl->Disconnect( ID_COPYTO_BASE, ID_COPYTO_BASE + guCOPYTO_MAXCOUNT, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnFolderCopyTo ), NULL, this );
 
1621
 
 
1622
    m_DirCtrl->Disconnect( ID_COMMANDS_BASE, ID_COMMANDS_BASE + guCOMMANDS_MAXCOUNT, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnFolderCommand ), NULL, this );
 
1623
 
 
1624
    Disconnect( ID_FILESYSTEM_ITEMS_PLAY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnItemsPlay ), NULL, this );
 
1625
    Disconnect( ID_FILESYSTEM_ITEMS_ENQUEUE_AFTER_ALL, ID_FILESYSTEM_ITEMS_ENQUEUE_AFTER_ARTIST, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnItemsEnqueue ), NULL, this );
 
1626
    Disconnect( ID_FILESYSTEM_ITEMS_EDITTRACKS, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnItemsEditTracks ), NULL, this );
 
1627
    Disconnect( ID_FILESYSTEM_ITEMS_SAVEPLAYLIST, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnItemsSaveToPlayList ), NULL, this );
 
1628
    m_FilesCtrl->Disconnect( ID_COPYTO_BASE, ID_COPYTO_BASE + guCOPYTO_MAXCOUNT, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnItemsCopyTo ), NULL, this );
 
1629
    Disconnect( ID_FILESYSTEM_ITEMS_RENAME, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnItemsRename ), NULL, this );
 
1630
    Disconnect( ID_FILESYSTEM_ITEMS_DELETE, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnItemsDelete ), NULL, this );
 
1631
 
 
1632
    m_FilesCtrl->Disconnect( ID_COMMANDS_BASE, ID_COMMANDS_BASE + guCOMMANDS_MAXCOUNT, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( guFileBrowser::OnItemsCommand ), NULL, this );
 
1633
 
 
1634
}
 
1635
 
 
1636
// -------------------------------------------------------------------------------- //
 
1637
void guFileBrowser::OnDirItemChanged( wxTreeEvent &event )
 
1638
{
 
1639
    wxString CurPath = m_DirCtrl->GetPath();
 
1640
    if( !CurPath.EndsWith( wxT( "/" ) ) )
 
1641
        CurPath.Append( wxT( "/" ) );
 
1642
 
 
1643
    guLogMessage( wxT( "guFileBrowser::OnDirItemChanged( '%s' )" ), CurPath.c_str() );
 
1644
 
 
1645
    if( m_DirCtrl->GetShowPaths() & guFILEBROWSER_SHOWPATH_LOCATIONS )
 
1646
    {
 
1647
        m_MediaViewer = FindMediaViewerByPath( m_MainFrame, CurPath );
 
1648
        m_Db = m_MediaViewer ? m_MediaViewer->GetDb() : NULL;
 
1649
        if( m_MediaViewer )
 
1650
            guLogMessage( wxT( "'%s' ==>> '%i' '%s'" ), CurPath.c_str(), m_MediaViewer != NULL, m_MediaViewer->GetName().c_str() );
 
1651
        else
 
1652
            guLogMessage( wxT( "'%s' ==>> '%i' ''" ), CurPath.c_str(), m_MediaViewer != NULL );
 
1653
    }
 
1654
    else
 
1655
    {
 
1656
        m_Db = NULL;
 
1657
    }
 
1658
 
 
1659
    m_FilesCtrl->SetPath( CurPath, m_MediaViewer );
 
1660
    m_DirCtrl->SetMediaViewer( m_MediaViewer );
 
1661
}
 
1662
 
 
1663
// -------------------------------------------------------------------------------- //
 
1664
void guFileBrowser::OnFileItemActivated( wxListEvent &Event )
 
1665
{
 
1666
    wxArrayInt Selection = m_FilesCtrl->GetSelectedItems( false );
 
1667
    if( Selection.Count() )
 
1668
    {
 
1669
        if( m_FilesCtrl->GetType( Selection[ 0 ] ) == guFILEITEM_TYPE_FOLDER )
 
1670
        {
 
1671
            m_DirCtrl->SetPath( m_FilesCtrl->GetPath( Selection[ 0 ] ), m_MediaViewer );
 
1672
        }
 
1673
        else
 
1674
        {
 
1675
            wxArrayString Files;
 
1676
            Files.Add( m_FilesCtrl->GetPath( Selection[ 0 ] ) );
 
1677
 
 
1678
            guConfig * Config = ( guConfig * ) guConfig::Get();
 
1679
            if( Config )
 
1680
            {
 
1681
                if( Config->ReadBool( wxT( "DefaultActionEnqueue" ), false , wxT( "general" )) )
 
1682
                {
 
1683
                    m_PlayerPanel->AddToPlayList( Files );
 
1684
                }
 
1685
                else
 
1686
                {
 
1687
                    m_PlayerPanel->SetPlayList( Files );
 
1688
                }
 
1689
            }
 
1690
 
 
1691
        }
 
1692
    }
 
1693
}
 
1694
 
 
1695
// -------------------------------------------------------------------------------- //
 
1696
void guFileBrowser::OnFilesColClick( wxListEvent &event )
 
1697
{
 
1698
    int col = event.GetColumn();
 
1699
    if( col < 0 )
 
1700
        return;
 
1701
    m_FilesCtrl->SetOrder( col );
 
1702
}
 
1703
 
 
1704
// -------------------------------------------------------------------------------- //
 
1705
void guFileBrowser::OnDirBeginDrag( wxTreeEvent &event )
 
1706
{
 
1707
    wxFileDataObject Files;
 
1708
 
 
1709
    wxArrayString FolderFiles = m_FilesCtrl->GetAllFiles( true );
 
1710
    int Index;
 
1711
    int Count;
 
1712
    if( ( Count = FolderFiles.Count() ) )
 
1713
    {
 
1714
        for( Index = 0; Index < Count; Index++ )
 
1715
        {
 
1716
            Files.AddFile( FolderFiles[ Index ] );
 
1717
        }
 
1718
 
 
1719
        wxDropSource source( Files, this );
 
1720
 
 
1721
        wxDragResult Result = source.DoDragDrop();
 
1722
        if( Result )
 
1723
        {
 
1724
        }
 
1725
    }
 
1726
}
 
1727
 
 
1728
// -------------------------------------------------------------------------------- //
 
1729
void guFileBrowser::OnFolderPlay( wxCommandEvent &event )
 
1730
{
 
1731
    wxArrayString Files = m_FilesCtrl->GetAllFiles( true );
 
1732
    m_PlayerPanel->SetPlayList( Files );
 
1733
}
 
1734
 
 
1735
// -------------------------------------------------------------------------------- //
 
1736
void guFileBrowser::OnFolderEnqueue( wxCommandEvent &event )
 
1737
{
 
1738
    wxArrayString Files = m_FilesCtrl->GetAllFiles( true );
 
1739
    if( Files.Count() )
 
1740
    {
 
1741
        m_PlayerPanel->AddToPlayList( Files, true, event.GetId() - ID_FILESYSTEM_FOLDER_ENQUEUE_AFTER_ALL );
 
1742
    }
 
1743
}
 
1744
 
 
1745
// -------------------------------------------------------------------------------- //
 
1746
void guFileBrowser::OnFolderNew( wxCommandEvent &event )
 
1747
{
 
1748
    m_DirCtrl->FolderNew();
 
1749
}
 
1750
 
 
1751
// -------------------------------------------------------------------------------- //
 
1752
void guFileBrowser::OnFolderRename( wxCommandEvent &event )
 
1753
{
 
1754
    m_DirCtrl->FolderRename();
 
1755
}
 
1756
 
 
1757
// -------------------------------------------------------------------------------- //
 
1758
void guFileBrowser::OnFolderDelete( wxCommandEvent &event )
 
1759
{
 
1760
    m_DirCtrl->FolderDelete();
 
1761
}
 
1762
 
 
1763
// -------------------------------------------------------------------------------- //
 
1764
void guFileBrowser::OnFolderCopy( wxCommandEvent &event )
 
1765
{
 
1766
    //guLogMessage( wxT( "OnFolderCopy" ) );
 
1767
    wxTheClipboard->UsePrimarySelection( false );
 
1768
    if( wxTheClipboard->Open() )
 
1769
    {
 
1770
        wxTheClipboard->Clear();
 
1771
        wxFileDataObject * FileObject = new wxFileDataObject();
 
1772
        //wxCustomDataObject * GnomeCopiedObject = new wxCustomDataObject( wxDataFormat( wxT( "x-special/gnome-copied-files" ) ) );
 
1773
        //wxCustomDataObject * UriListObject = new wxCustomDataObject( wxDataFormat( wxT( "text/uri-list" ) ) );
 
1774
        wxTextDataObject * TextObject = new wxTextDataObject();
 
1775
        wxDataObjectComposite * CompositeObject = new wxDataObjectComposite();
 
1776
 
 
1777
        wxString Path = m_DirCtrl->GetPath();
 
1778
        Path.Replace( wxT( "#" ), wxT( "%23" ) );
 
1779
 
 
1780
        TextObject->SetText( Path );
 
1781
        FileObject->AddFile( Path );
 
1782
 
 
1783
        //Path = wxT( "file://" ) + Path;
 
1784
        //UriListObject->SetData( Path.Length(), Path.char_str() );
 
1785
 
 
1786
        //Path = wxT( "copy\n" ) + Path;
 
1787
        //GnomeCopiedObject->SetData( Path.Length(), Path.char_str() );
 
1788
 
 
1789
        //guLogMessage( wxT( "Copy: '%s'" ), Path.c_str() );
 
1790
 
 
1791
        CompositeObject->Add( FileObject );
 
1792
        //CompositeObject->Add( GnomeCopiedObject );
 
1793
        //CompositeObject->Add( UriListObject );
 
1794
        CompositeObject->Add( TextObject );
 
1795
 
 
1796
        //if( !wxTheClipboard->AddData( CustomObject ) )
 
1797
        if( !wxTheClipboard->AddData( CompositeObject ) )
 
1798
        //if( !wxTheClipboard->AddData( TextObject ) )
 
1799
        {
 
1800
            delete FileObject;
 
1801
            delete TextObject;
 
1802
            //delete GnomeCopiedObject;
 
1803
            //delete UriListObject;
 
1804
            delete CompositeObject;
 
1805
            guLogError( wxT( "Can't copy the folder to the clipboard" ) );
 
1806
        }
 
1807
        guLogMessage( wxT( "Copied the data to the clipboard..." ) );
 
1808
        wxTheClipboard->Close();
 
1809
    }
 
1810
    else
 
1811
    {
 
1812
        guLogError( wxT( "Could not open the clipboard object" ) );
 
1813
    }
 
1814
}
 
1815
 
 
1816
// -------------------------------------------------------------------------------- //
 
1817
void guFileBrowser::OnFolderPaste( wxCommandEvent &event )
 
1818
{
 
1819
    guLogMessage( wxT( "OnFolderPaste" ) );
 
1820
    wxTheClipboard->UsePrimarySelection( false );
 
1821
    if( wxTheClipboard->Open() )
 
1822
    {
 
1823
 
 
1824
//        if( wxTheClipboard->IsSupported( wxDataFormat(  wxT( "text/uri-list" ) ) ) )
 
1825
//        {
 
1826
//            guLogMessage( wxT( "Supported format uri-list.." ) );
 
1827
//
 
1828
//            wxCustomDataObject CustomDataObject( wxDataFormat( wxT( "text/uri-list" ) ) );
 
1829
//            if( wxTheClipboard->GetData( CustomDataObject ) )
 
1830
//            {
 
1831
//                guLogMessage( wxT( "Custom Data: (%i) '%s'" ), CustomDataObject.GetSize(), wxString( ( const char * ) CustomDataObject.GetData(), wxConvUTF8 ).c_str() );
 
1832
//            }
 
1833
//        }
 
1834
//
 
1835
//        if( wxTheClipboard->IsSupported( wxDataFormat( wxT( "x-special/gnome-copied-files" ) ) ) )
 
1836
//        {
 
1837
//            guLogMessage( wxT( "Supported format x-special..." ) );
 
1838
//
 
1839
//            wxCustomDataObject CustomDataObject( wxDataFormat( wxT( "x-special/gnome-copied-files" ) ) ); //( wxT( "Supported format x-special..." ) );
 
1840
//            if( wxTheClipboard->GetData( CustomDataObject ) )
 
1841
//            {
 
1842
//                guLogMessage( wxT( "Custom Data: (%i) '%s'" ), CustomDataObject.GetSize(), wxString( ( const char * ) CustomDataObject.GetData(), wxConvUTF8 ).c_str() );
 
1843
//            }
 
1844
//        }
 
1845
//        else if( wxTheClipboard->IsSupported( wxDF_FILENAME ) )
 
1846
        if( wxTheClipboard->IsSupported( wxDF_FILENAME ) )
 
1847
        {
 
1848
            wxFileDataObject FileObject;
 
1849
            if( wxTheClipboard->GetData( FileObject ) )
 
1850
            {
 
1851
                wxArrayString Files = FileObject.GetFilenames();
 
1852
                wxArrayString FromFiles;
 
1853
                //guLogMessage( wxT( "Pasted: %s" ), Files[ 0 ].c_str() );
 
1854
                int Index;
 
1855
                int Count = Files.Count();
 
1856
                for( Index = 0; Index < Count; Index++ )
 
1857
                {
 
1858
                    if( wxDirExists( Files[ Index ] ) )
 
1859
                    {
 
1860
                        //wxFileName::Mkdir( m_DirCtrl->GetPath() + wxT( "/" ) + wxFileNameFromPath( Files[ Index ] ), 0770, wxPATH_MKDIR_FULL );
 
1861
 
 
1862
                        guAddDirItems( Files[ Index ], FromFiles );
 
1863
 
 
1864
                        int FromIndex;
 
1865
                        int FromCount = FromFiles.Count();
 
1866
                        for( FromIndex = 0; FromIndex < FromCount; FromIndex++ )
 
1867
                        {
 
1868
                            wxString DestName = FromFiles[ FromIndex ];
 
1869
                            DestName.Replace( wxPathOnly( Files[ Index ] ), m_DirCtrl->GetPath() );
 
1870
                            wxFileName::Mkdir( wxPathOnly( DestName ), 0770, wxPATH_MKDIR_FULL );
 
1871
                            guLogMessage( wxT( "Copy file %s to %s" ), FromFiles[ FromIndex ].c_str(), DestName.c_str() );
 
1872
                            wxCopyFile( FromFiles[ FromIndex ], DestName );
 
1873
                        }
 
1874
 
 
1875
                    }
 
1876
                    else
 
1877
                    {
 
1878
                        wxCopyFile( Files[ Index ], m_DirCtrl->GetPath() + wxT( "/" ) + wxFileNameFromPath( Files[ Index ] ) );
 
1879
                    }
 
1880
                }
 
1881
                wxString CurPath = m_DirCtrl->GetPath();
 
1882
                m_DirCtrl->CollapsePath( CurPath );
 
1883
                m_DirCtrl->ExpandPath( CurPath );
 
1884
            }
 
1885
            else
 
1886
            {
 
1887
                guLogError( wxT( "Can't paste the data from the clipboard" ) );
 
1888
            }
 
1889
 
 
1890
        }
 
1891
        wxTheClipboard->Close();
 
1892
    }
 
1893
    else
 
1894
    {
 
1895
        guLogError( wxT( "Could not open the clipboard object" ) );
 
1896
    }
 
1897
}
 
1898
 
 
1899
// -------------------------------------------------------------------------------- //
 
1900
void guFileBrowser::OnFolderEditTracks( wxCommandEvent &event )
 
1901
{
 
1902
    guTrackArray Tracks;
 
1903
    guImagePtrArray Images;
 
1904
    wxArrayString Lyrics;
 
1905
    wxArrayInt ChangedFlags;
 
1906
 
 
1907
    m_FilesCtrl->GetAllSongs( &Tracks );
 
1908
 
 
1909
    if( Tracks.Count() )
 
1910
    {
 
1911
        guTrackEditor * TrackEditor = new guTrackEditor( this, m_Db ? m_Db : m_DefaultDb, &Tracks, &Images, &Lyrics, &ChangedFlags );
 
1912
 
 
1913
        if( TrackEditor )
 
1914
        {
 
1915
            if( TrackEditor->ShowModal() == wxID_OK )
 
1916
            {
 
1917
                guUpdateTracks( Tracks, Images, Lyrics, ChangedFlags );
 
1918
                if( m_Db )
 
1919
                    m_Db->UpdateSongs( &Tracks, ChangedFlags );
 
1920
                else
 
1921
                    m_DefaultDb->UpdateSongs( &Tracks, ChangedFlags );
 
1922
                //guUpdateLyrics( Tracks, Lyrics, ChangedFlags );
 
1923
                //guUpdateImages( Tracks, Images, ChangedFlags );
 
1924
 
 
1925
                // Update the track in database, playlist, etc
 
1926
                m_MainFrame->UpdatedTracks( guUPDATED_TRACKS_PLAYER_PLAYLIST, &Tracks );
 
1927
            }
 
1928
            guImagePtrArrayClean( &Images );
 
1929
            TrackEditor->Destroy();
 
1930
        }
 
1931
    }
 
1932
}
 
1933
 
 
1934
// -------------------------------------------------------------------------------- //
 
1935
void guFileBrowser::OnFolderSaveToPlayList( wxCommandEvent &event )
 
1936
{
 
1937
    guTrackArray Tracks;
 
1938
 
 
1939
    m_FilesCtrl->GetAllSongs( &Tracks );
 
1940
    wxArrayInt TrackIds;
 
1941
    int Index;
 
1942
    int Count = Tracks.Count();
 
1943
    for( Index = 0; Index < Count; Index++ )
 
1944
    {
 
1945
        TrackIds.Add( Tracks[ Index ].m_SongId );
 
1946
    }
 
1947
 
 
1948
    if( m_Db && TrackIds.Count() )
 
1949
    {
 
1950
        guListItems PlayLists;
 
1951
        m_Db->GetPlayLists( &PlayLists,guPLAYLIST_TYPE_STATIC );
 
1952
        guPlayListAppend * PlayListAppendDlg = new guPlayListAppend( m_MainFrame, m_Db, &TrackIds, &PlayLists );
 
1953
        if( PlayListAppendDlg->ShowModal() == wxID_OK )
 
1954
        {
 
1955
            int Selected = PlayListAppendDlg->GetSelectedPlayList();
 
1956
            if( Selected == -1 )
 
1957
            {
 
1958
                wxString PLName = PlayListAppendDlg->GetPlaylistName();
 
1959
                if( PLName.IsEmpty() )
 
1960
                {
 
1961
                    PLName = _( "UnNamed" );
 
1962
                }
 
1963
                m_Db->CreateStaticPlayList( PLName, TrackIds );
 
1964
            }
 
1965
            else
 
1966
            {
 
1967
                int PLId = PlayLists[ Selected ].m_Id;
 
1968
                wxArrayInt OldSongs;
 
1969
                m_Db->GetPlayListSongIds( PLId, &OldSongs );
 
1970
                if( PlayListAppendDlg->GetSelectedPosition() == 0 ) // BEGIN
 
1971
                {
 
1972
                    m_Db->UpdateStaticPlayList( PLId, TrackIds );
 
1973
                    m_Db->AppendStaticPlayList( PLId, OldSongs );
 
1974
                }
 
1975
                else                                                // END
 
1976
                {
 
1977
                    m_Db->AppendStaticPlayList( PLId, TrackIds );
 
1978
                }
 
1979
            }
 
1980
 
 
1981
            m_MediaViewer->UpdatePlaylists();
 
1982
        }
 
1983
 
 
1984
        PlayListAppendDlg->Destroy();
 
1985
    }
 
1986
}
 
1987
 
 
1988
// -------------------------------------------------------------------------------- //
 
1989
void guFileBrowser::OnFolderCopyTo( wxCommandEvent &event )
 
1990
{
 
1991
    guTrackArray * Tracks = new guTrackArray();
 
1992
    m_FilesCtrl->GetAllSongs( Tracks );
 
1993
 
 
1994
    int Index = event.GetId() - ID_COPYTO_BASE;
 
1995
    if( Index >= guCOPYTO_DEVICE_BASE )
 
1996
    {
 
1997
        Index -= guCOPYTO_DEVICE_BASE;
 
1998
        event.SetId( ID_MAINFRAME_COPYTODEVICE_TRACKS );
 
1999
    }
 
2000
    else
 
2001
    {
 
2002
        event.SetId( ID_MAINFRAME_COPYTO );
 
2003
    }
 
2004
    event.SetInt( Index );
 
2005
    event.SetClientData( ( void * ) Tracks );
 
2006
    wxPostEvent( m_MainFrame, event );
 
2007
}
 
2008
 
 
2009
// -------------------------------------------------------------------------------- //
 
2010
void guFileBrowser::OnItemsPlay( wxCommandEvent &event )
 
2011
{
 
2012
    wxArrayString Files = m_FilesCtrl->GetSelectedFiles( true );
 
2013
 
 
2014
    int Index;
 
2015
    int Count = Files.Count();
 
2016
    for( Index = 0; Index < Count; Index++ )
 
2017
    {
 
2018
        guLogMessage( wxT( "File%i: '%s'" ), Index, Files[ Index ].c_str() );
 
2019
    }
 
2020
    if( Files.Count() )
 
2021
    {
 
2022
        m_PlayerPanel->SetPlayList( Files );
 
2023
    }
 
2024
}
 
2025
 
 
2026
// -------------------------------------------------------------------------------- //
 
2027
void guFileBrowser::OnItemsEnqueue( wxCommandEvent &event )
 
2028
{
 
2029
    wxArrayString Files = m_FilesCtrl->GetSelectedFiles( true );
 
2030
    if( Files.Count() )
 
2031
    {
 
2032
        m_PlayerPanel->AddToPlayList( Files, true, event.GetId() - ID_FILESYSTEM_ITEMS_ENQUEUE_AFTER_ALL );
 
2033
    }
 
2034
}
 
2035
 
 
2036
// -------------------------------------------------------------------------------- //
 
2037
void guFileBrowser::OnItemsEditTracks( wxCommandEvent &event )
 
2038
{
 
2039
    guTrackArray Tracks;
 
2040
    guImagePtrArray Images;
 
2041
    wxArrayString Lyrics;
 
2042
    wxArrayInt ChangedFlags;
 
2043
 
 
2044
    m_FilesCtrl->GetSelectedSongs( &Tracks );
 
2045
 
 
2046
    if( Tracks.Count() )
 
2047
    {
 
2048
        guTrackEditor * TrackEditor = new guTrackEditor( this, m_Db ? m_Db : m_DefaultDb, &Tracks, &Images, &Lyrics, &ChangedFlags );
 
2049
 
 
2050
        if( TrackEditor )
 
2051
        {
 
2052
            if( TrackEditor->ShowModal() == wxID_OK )
 
2053
            {
 
2054
                guUpdateTracks( Tracks, Images, Lyrics, ChangedFlags );
 
2055
                if( m_Db )
 
2056
                    m_Db->UpdateSongs( &Tracks, ChangedFlags );
 
2057
                else
 
2058
                    m_DefaultDb->UpdateSongs( &Tracks, ChangedFlags );
 
2059
                //guUpdateLyrics( Tracks, Lyrics, ChangedFlags );
 
2060
                //guUpdateImages( Tracks, Images, ChangedFlags );
 
2061
 
 
2062
                // Update the track in database, playlist, etc
 
2063
                m_MainFrame->UpdatedTracks( guUPDATED_TRACKS_PLAYER_PLAYLIST, &Tracks );
 
2064
            }
 
2065
            guImagePtrArrayClean( &Images );
 
2066
            TrackEditor->Destroy();
 
2067
        }
 
2068
    }
 
2069
}
 
2070
 
 
2071
// -------------------------------------------------------------------------------- //
 
2072
void guFileBrowser::OnItemsSaveToPlayList( wxCommandEvent &event )
 
2073
{
 
2074
    guTrackArray Tracks;
 
2075
    m_FilesCtrl->GetSelectedSongs( &Tracks );
 
2076
 
 
2077
    wxArrayInt TrackIds;
 
2078
    int Index;
 
2079
    int Count = Tracks.Count();
 
2080
    for( Index = 0; Index < Count; Index++ )
 
2081
    {
 
2082
        TrackIds.Add( Tracks[ Index ].m_SongId );
 
2083
    }
 
2084
 
 
2085
    if( m_Db && TrackIds.Count() )
 
2086
    {
 
2087
        guListItems PlayLists;
 
2088
        m_Db->GetPlayLists( &PlayLists, guPLAYLIST_TYPE_STATIC );
 
2089
        guPlayListAppend * PlayListAppendDlg = new guPlayListAppend( m_MainFrame, m_Db, &TrackIds, &PlayLists );
 
2090
        if( PlayListAppendDlg->ShowModal() == wxID_OK )
 
2091
        {
 
2092
            int Selected = PlayListAppendDlg->GetSelectedPlayList();
 
2093
            if( Selected == -1 )
 
2094
            {
 
2095
                wxString PLName = PlayListAppendDlg->GetPlaylistName();
 
2096
                if( PLName.IsEmpty() )
 
2097
                {
 
2098
                    PLName = _( "UnNamed" );
 
2099
                }
 
2100
                m_Db->CreateStaticPlayList( PLName, TrackIds );
 
2101
            }
 
2102
            else
 
2103
            {
 
2104
                int PLId = PlayLists[ Selected ].m_Id;
 
2105
                wxArrayInt OldSongs;
 
2106
                m_Db->GetPlayListSongIds( PLId, &OldSongs );
 
2107
                if( PlayListAppendDlg->GetSelectedPosition() == 0 ) // BEGIN
 
2108
                {
 
2109
                    m_Db->UpdateStaticPlayList( PLId, TrackIds );
 
2110
                    m_Db->AppendStaticPlayList( PLId, OldSongs );
 
2111
                }
 
2112
                else                                                // END
 
2113
                {
 
2114
                    m_Db->AppendStaticPlayList( PLId, TrackIds );
 
2115
                }
 
2116
            }
 
2117
 
 
2118
            m_MediaViewer->UpdatePlaylists();
 
2119
        }
 
2120
 
 
2121
        PlayListAppendDlg->Destroy();
 
2122
    }
 
2123
}
 
2124
 
 
2125
// -------------------------------------------------------------------------------- //
 
2126
void guFileBrowser::OnItemsCopyTo( wxCommandEvent &event )
 
2127
{
 
2128
    guTrackArray * Tracks = new guTrackArray();
 
2129
    m_FilesCtrl->GetSelectedSongs( Tracks );
 
2130
 
 
2131
    int Index = event.GetId() - ID_COPYTO_BASE;
 
2132
    if( Index >= guCOPYTO_DEVICE_BASE )
 
2133
    {
 
2134
        Index -= guCOPYTO_DEVICE_BASE;
 
2135
        event.SetId( ID_MAINFRAME_COPYTODEVICE_TRACKS );
 
2136
    }
 
2137
    else
 
2138
    {
 
2139
        event.SetId( ID_MAINFRAME_COPYTO );
 
2140
    }
 
2141
    event.SetInt( Index );
 
2142
    event.SetClientData( ( void * ) Tracks );
 
2143
    wxPostEvent( m_MainFrame, event );
 
2144
}
 
2145
 
 
2146
// -------------------------------------------------------------------------------- //
 
2147
void guFileBrowser::OnItemsRename( wxCommandEvent &event )
 
2148
{
 
2149
    wxArrayString Files = m_FilesCtrl->GetSelectedFiles( true );
 
2150
    if( Files.Count() )
 
2151
    {
 
2152
        guFileRenamer * FileRenamer = new guFileRenamer( this, m_Db ? m_Db : m_DefaultDb, Files );
 
2153
        if( FileRenamer )
 
2154
        {
 
2155
            if( FileRenamer->ShowModal() == wxID_OK )
 
2156
            {
 
2157
                wxArrayString RenamedFiles = FileRenamer->GetRenamedNames();
 
2158
                int Index;
 
2159
                int Count = RenamedFiles.Count();
 
2160
                for( Index = 0; Index < Count; Index++ )
 
2161
                {
 
2162
                    if( Files[ Index ] != RenamedFiles[ Index ] )
 
2163
                    {
 
2164
                        wxString NewDirName = wxPathOnly( RenamedFiles[ Index ] );
 
2165
                        if( !wxDirExists( NewDirName ) )
 
2166
                        {
 
2167
                            wxFileName::Mkdir( NewDirName, 0770, wxPATH_MKDIR_FULL );
 
2168
                        }
 
2169
 
 
2170
                        //if( wxFileExists( Files[ Index ] ) )
 
2171
                        if( !guRenameFile( Files[ Index ], RenamedFiles[ Index ] ) )
 
2172
                        {
 
2173
                            guLogError( wxT( "Could no rename '%s' to '%s'" ),
 
2174
                                Files[ Index ].c_str(),
 
2175
                                RenamedFiles[ Index ].c_str() );
 
2176
                        }
 
2177
 
 
2178
                        if( m_Db )
 
2179
                            m_Db->UpdateTrackFileName( Files[ Index ], RenamedFiles[ Index ] );
 
2180
                        else
 
2181
                            m_DefaultDb->UpdateTrackFileName( Files[ Index ], RenamedFiles[ Index ] );
 
2182
                    }
 
2183
                }
 
2184
 
 
2185
                //m_DirCtrl->ExpandPath( m_DirCtrl->GetPath() );
 
2186
                m_FilesCtrl->SetPath( m_DirCtrl->GetPath(), m_MediaViewer );
 
2187
            }
 
2188
            FileRenamer->Destroy();
 
2189
        }
 
2190
    }
 
2191
}
 
2192
 
 
2193
// -------------------------------------------------------------------------------- //
 
2194
void guFileBrowser::OnItemsDelete( wxCommandEvent &event )
 
2195
{
 
2196
    wxArrayString Files = m_FilesCtrl->GetSelectedFiles();
 
2197
 
 
2198
    int Index;
 
2199
    int Count;
 
2200
    bool Error = false;
 
2201
    if( ( Count = Files.Count() ) )
 
2202
    {
 
2203
        if( wxMessageBox( _( "Are you sure to delete the selected files ?" ),
 
2204
                         _( "Confirm" ),
 
2205
                         wxICON_QUESTION | wxYES_NO, this ) == wxYES )
 
2206
        {
 
2207
            wxArrayString DeleteFiles;
 
2208
            for( Index = 0; Index < Count; Index++ )
 
2209
            {
 
2210
                if( wxDirExists( Files[ Index ] ) )
 
2211
                {
 
2212
                    Error = !RemoveDirItems( Files[ Index ], &DeleteFiles ) || !wxRmdir( Files[ Index ] );
 
2213
                }
 
2214
                else
 
2215
                {
 
2216
                    Error = !wxRemoveFile( Files[ Index ] );
 
2217
                    DeleteFiles.Add( Files[ Index ] );
 
2218
                }
 
2219
                if( Error )
 
2220
                {
 
2221
                    if( wxMessageBox( _( "There was an error deleting " ) + wxFileNameFromPath( Files[ Index ] ) +
 
2222
                                      _( "\nContinue deleting?" ),
 
2223
                                     _( "Continue" ),
 
2224
                                     wxICON_QUESTION | wxYES_NO, this ) == wxNO )
 
2225
                    {
 
2226
                        break;
 
2227
                    }
 
2228
                    //Error = false;
 
2229
                }
 
2230
            }
 
2231
            wxString CurrentFolder = m_DirCtrl->GetPath();
 
2232
            m_DirCtrl->CollapsePath( CurrentFolder );
 
2233
            m_DirCtrl->ExpandPath( CurrentFolder );
 
2234
            //
 
2235
            //m_Db->DoCleanUp();
 
2236
            if( m_Db )
 
2237
                m_Db->CleanFiles( DeleteFiles );
 
2238
            else
 
2239
                m_DefaultDb->CleanFiles( DeleteFiles );
 
2240
        }
 
2241
    }
 
2242
}
 
2243
 
 
2244
// -------------------------------------------------------------------------------- //
 
2245
void guFileBrowser::OnFolderCommand( wxCommandEvent &event )
 
2246
{
 
2247
    int Index;
 
2248
    int Count;
 
2249
    Index = event.GetId();
 
2250
 
 
2251
    guConfig * Config = ( guConfig * ) Config->Get();
 
2252
    if( Config )
 
2253
    {
 
2254
        wxArrayString Commands = Config->ReadAStr( wxT( "Exec" ), wxEmptyString, wxT( "commands/execs" ) );
 
2255
 
 
2256
        Index -= ID_COMMANDS_BASE;
 
2257
        wxString CurCmd = Commands[ Index ];
 
2258
        if( CurCmd.Find( wxT( "{bp}" ) ) != wxNOT_FOUND )
 
2259
        {
 
2260
            wxString DirPath = m_DirCtrl->GetPath();
 
2261
            DirPath.Replace( wxT( " " ), wxT( "\\ " ) );
 
2262
            CurCmd.Replace( wxT( "{bp}" ), DirPath );
 
2263
        }
 
2264
 
 
2265
        if( CurCmd.Find( wxT( "{tp}" ) ) != wxNOT_FOUND )
 
2266
        {
 
2267
            wxString SongList;
 
2268
            wxArrayString Files = m_FilesCtrl->GetAllFiles( true );
 
2269
            Count = Files.Count();
 
2270
            for( Index = 0; Index < Count; Index++ )
 
2271
            {
 
2272
                SongList += wxT( " \"" ) + Files[ Index ] + wxT( "\"" );
 
2273
            }
 
2274
            CurCmd.Replace( wxT( "{tp}" ), SongList.Trim( false ) );
 
2275
        }
 
2276
 
 
2277
        //guLogMessage( wxT( "Execute Command '%s'" ), CurCmd.c_str() );
 
2278
        guExecute( CurCmd );
 
2279
    }
 
2280
}
 
2281
 
 
2282
// -------------------------------------------------------------------------------- //
 
2283
void guFileBrowser::OnItemsCommand( wxCommandEvent &event )
 
2284
{
 
2285
    int Index;
 
2286
    int Count;
 
2287
    Index = event.GetId();
 
2288
 
 
2289
    guConfig * Config = ( guConfig * ) Config->Get();
 
2290
    if( Config )
 
2291
    {
 
2292
        wxArrayString Commands = Config->ReadAStr( wxT( "Exec" ), wxEmptyString, wxT( "commands/execs" ) );
 
2293
 
 
2294
        Index -= ID_COMMANDS_BASE;
 
2295
        wxString CurCmd = Commands[ Index ];
 
2296
        if( CurCmd.Find( wxT( "{bp}" ) ) != wxNOT_FOUND )
 
2297
        {
 
2298
            wxString DirPath = m_DirCtrl->GetPath();
 
2299
            DirPath.Replace( wxT( " " ), wxT( "\\ " ) );
 
2300
            CurCmd.Replace( wxT( "{bp}" ), DirPath );
 
2301
        }
 
2302
 
 
2303
        if( CurCmd.Find( wxT( "{bc}" ) ) != wxNOT_FOUND )
 
2304
        {
 
2305
            wxString SongList;
 
2306
            wxArrayString Files = m_FilesCtrl->GetSelectedFiles( false );
 
2307
            Count = Files.Count();
 
2308
            for( Index = 0; Index < Count; Index++ )
 
2309
            {
 
2310
                SongList += wxT( " \"" ) + Files[ Index ] + wxT( "\"" );
 
2311
            }
 
2312
            CurCmd.Replace( wxT( "{bc}" ), SongList.Trim( false ) );
 
2313
        }
 
2314
 
 
2315
        if( CurCmd.Find( wxT( "{tp}" ) ) != wxNOT_FOUND )
 
2316
        {
 
2317
            wxString SongList;
 
2318
            wxArrayString Files = m_FilesCtrl->GetSelectedFiles( true );
 
2319
            Count = Files.Count();
 
2320
            for( Index = 0; Index < Count; Index++ )
 
2321
            {
 
2322
                SongList += wxT( " \"" ) + Files[ Index ] + wxT( "\"" );
 
2323
            }
 
2324
            CurCmd.Replace( wxT( "{tp}" ), SongList.Trim( false ) );
 
2325
        }
 
2326
 
 
2327
        //guLogMessage( wxT( "Execute Command '%s'" ), CurCmd.c_str() );
 
2328
        guExecute( CurCmd );
 
2329
    }
 
2330
}
 
2331
 
 
2332
// -------------------------------------------------------------------------------- //
 
2333
void guFileBrowser::OnItemsCopy( wxCommandEvent &event )
 
2334
{
 
2335
    wxArrayString Files = m_FilesCtrl->GetSelectedFiles( false );
 
2336
    if( Files.Count() )
 
2337
    {
 
2338
        wxTheClipboard->UsePrimarySelection( false );
 
2339
        if( wxTheClipboard->Open() )
 
2340
        {
 
2341
            wxTheClipboard->Clear();
 
2342
            wxFileDataObject * FileObject = new wxFileDataObject();
 
2343
            wxTextDataObject * TextObject = new wxTextDataObject();
 
2344
            wxDataObjectComposite * CompositeObject = new wxDataObjectComposite();
 
2345
 
 
2346
            wxString FilesText;
 
2347
            int Index;
 
2348
            int Count = Files.Count();
 
2349
            for( Index = 0; Index < Count; Index++ )
 
2350
            {
 
2351
                wxString CurFile = Files[ Index ];
 
2352
                FilesText += ( FilesText.IsEmpty() ? wxT( "" ) : wxT( "\n" ) ) + CurFile;
 
2353
 
 
2354
                CurFile.Replace( wxT( "#" ), wxT( "%23" ) );
 
2355
                FileObject->AddFile( CurFile );
 
2356
            }
 
2357
 
 
2358
            TextObject->SetText( FilesText );
 
2359
 
 
2360
            CompositeObject->Add( FileObject );
 
2361
            CompositeObject->Add( TextObject );
 
2362
 
 
2363
            if( !wxTheClipboard->AddData( CompositeObject ) )
 
2364
            {
 
2365
                delete FileObject;
 
2366
                delete TextObject;
 
2367
                delete CompositeObject;
 
2368
                guLogError( wxT( "Can't copy the selected files to the clipboard" ) );
 
2369
            }
 
2370
            wxTheClipboard->Close();
 
2371
        }
 
2372
        else
 
2373
        {
 
2374
            guLogError( wxT( "Could not open the clipboard object" ) );
 
2375
        }
 
2376
    }
 
2377
}
 
2378
 
 
2379
// -------------------------------------------------------------------------------- //
 
2380
void guFileBrowser::OnItemsPaste( wxCommandEvent &event )
 
2381
{
 
2382
    wxString DestFolder;
 
2383
    wxTheClipboard->UsePrimarySelection( false );
 
2384
    if( wxTheClipboard->Open() )
 
2385
    {
 
2386
        if( wxTheClipboard->IsSupported( wxDF_FILENAME ) )
 
2387
        {
 
2388
            wxArrayString Selection = m_FilesCtrl->GetSelectedFiles( false );
 
2389
            if( ( Selection.Count() == 1 ) && wxDirExists( Selection[ 0 ] ) )
 
2390
            {
 
2391
                DestFolder = Selection[ 0 ];
 
2392
            }
 
2393
            else
 
2394
            {
 
2395
                DestFolder = m_DirCtrl->GetPath();
 
2396
            }
 
2397
 
 
2398
            wxFileDataObject FileObject;
 
2399
            if( wxTheClipboard->GetData( FileObject ) )
 
2400
            {
 
2401
                wxArrayString Files = FileObject.GetFilenames();
 
2402
                wxArrayString FromFiles;
 
2403
                //guLogMessage( wxT( "Pasted: %s" ), Files[ 0 ].c_str() );
 
2404
                int Index;
 
2405
                int Count = Files.Count();
 
2406
                for( Index = 0; Index < Count; Index++ )
 
2407
                {
 
2408
                    if( wxDirExists( Files[ Index ] ) )
 
2409
                    {
 
2410
                        guAddDirItems( Files[ Index ], FromFiles );
 
2411
 
 
2412
                        int FromIndex;
 
2413
                        int FromCount = FromFiles.Count();
 
2414
                        for( FromIndex = 0; FromIndex < FromCount; FromIndex++ )
 
2415
                        {
 
2416
                            wxString DestName = FromFiles[ FromIndex ];
 
2417
                            DestName.Replace( wxPathOnly( Files[ Index ] ), DestFolder );
 
2418
                            wxFileName::Mkdir( wxPathOnly( DestName ), 0770, wxPATH_MKDIR_FULL );
 
2419
                            guLogMessage( wxT( "Copy file %s to %s" ), FromFiles[ FromIndex ].c_str(), DestName.c_str() );
 
2420
                            wxCopyFile( FromFiles[ FromIndex ], DestName );
 
2421
                        }
 
2422
                    }
 
2423
                    else
 
2424
                    {
 
2425
                        wxCopyFile( Files[ Index ], m_DirCtrl->GetPath() + wxT( "/" ) + wxFileNameFromPath( Files[ Index ] ) );
 
2426
                    }
 
2427
                }
 
2428
                wxString CurPath = m_DirCtrl->GetPath();
 
2429
                m_DirCtrl->CollapsePath( CurPath );
 
2430
                m_DirCtrl->ExpandPath( CurPath );
 
2431
            }
 
2432
            else
 
2433
            {
 
2434
                guLogError( wxT( "Can't paste the data from the clipboard" ) );
 
2435
            }
 
2436
        }
 
2437
        wxTheClipboard->Close();
 
2438
    }
 
2439
    else
 
2440
    {
 
2441
        guLogError( wxT( "Could not open the clipboard object" ) );
 
2442
    }
 
2443
}
 
2444
 
 
2445
// -------------------------------------------------------------------------------- //