~ubuntu-branches/ubuntu/raring/codeblocks/raring-proposed

« back to all changes in this revision

Viewing changes to src/plugins/contrib/lib_finder/processingdlg.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Cosme Domínguez Díaz
  • Date: 2010-08-09 04:38:38 UTC
  • mfrom: (1.1.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20100809043838-a59ygguym4eg0jgw
Tags: 10.05-0ubuntu1
* New upstream release. Closes (LP: #322350)
 - Switch to dpkg-source 3.0 (quilt) format
 - Remove unneeded README.source
 - Add debian/get-source-orig script that removes all
   Windows prebuilt binaries
* Bump Standards-Version to 3.9.1
 - Stop shipping *.la files
* debian/control
 - Add cdbs package as Build-Depend
 - Add libbz2-dev and zlib1g-dev packages as
   Build-Depends (needed by libhelp_plugin.so)
 - Remove dpatch package of Build-Depends
 - Add codeblocks-contrib-debug package
 - Split architecture-independent files of codeblocks
   package in codeblocks-common package
* debian/rules
 - Switch to CDBS rules system
 - Add parallel build support
 - Add a call to debian/get-source-orig script
 - Use lzma compression (saves 23,5 MB of free space)
* debian/patches
 - Refresh 01_codeblocks_plugin_path
 - Add 02_no_Makefiles_in_debian_dir to remove any link
   in codeblocks build system to deleted Makefiles of debian directory
 - Drop 02_ftbfs_gcc44 and 03_ftbfs_glib221 (merged in upstream)
* debian/watch
 - Update to use the new host (berlios.de)

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
#include <prep.h>
32
32
 
33
33
//(*InternalHeaders(ProcessingDlg)
 
34
#include <wx/gauge.h>
 
35
#include <wx/sizer.h>
 
36
#include <wx/button.h>
 
37
#include <wx/string.h>
34
38
#include <wx/intl.h>
35
 
#include <wx/string.h>
 
39
#include <wx/stattext.h>
36
40
//*)
37
41
 
38
 
#include "libraryconfigmanager.h"
 
42
#include "librarydetectionmanager.h"
39
43
#include "resultmap.h"
40
44
#include "lib_finder.h"
 
45
#include "libselectdlg.h"
41
46
 
42
47
//(*IdInit(ProcessingDlg)
43
48
const long ProcessingDlg::ID_STATICTEXT1 = wxNewId();
45
50
const long ProcessingDlg::ID_BUTTON1 = wxNewId();
46
51
//*)
47
52
 
48
 
BEGIN_EVENT_TABLE(ProcessingDlg,wxDialog)
 
53
BEGIN_EVENT_TABLE(ProcessingDlg,wxScrollingDialog)
49
54
        //(*EventTable(ProcessingDlg)
50
55
        //*)
51
56
END_EVENT_TABLE()
52
57
 
53
 
ProcessingDlg::ProcessingDlg(wxWindow* parent,LibraryConfigManager& Manager,TypedResults& KnownResults,ResultMap& FoundResults,wxWindowID id):
 
58
ProcessingDlg::ProcessingDlg(wxWindow* parent,LibraryDetectionManager& Manager,TypedResults& KnownResults,wxWindowID id):
54
59
    StopFlag(false),
55
60
    m_Manager(Manager),
56
 
    m_KnownResults(KnownResults),
57
 
    m_FoundResults(FoundResults)
 
61
    m_KnownResults(KnownResults)
58
62
{
59
63
        //(*Initialize(ProcessingDlg)
60
64
        Create(parent, id, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxCAPTION, _T("id"));
70
74
        SetSizer(FlexGridSizer1);
71
75
        FlexGridSizer1->Fit(this);
72
76
        FlexGridSizer1->SetSizeHints(this);
73
 
 
 
77
        
74
78
        Connect(ID_BUTTON1,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&ProcessingDlg::OnButton1Click);
75
79
        //*)
76
80
}
143
147
 
144
148
bool ProcessingDlg::ProcessLibs()
145
149
{
146
 
    Gauge1->SetRange(m_Manager.GetLibraryCount());
147
 
 
148
 
    for ( int i=0; i<m_Manager.GetLibraryCount(); ++i )
 
150
    int TotalCount = 0;
 
151
    for ( int i=0; i<m_Manager.GetLibraryCount(); ++i )
 
152
    {
 
153
        TotalCount += (int)m_Manager.GetLibrary(i)->Configurations.size();
 
154
    }
 
155
 
 
156
    Gauge1->SetRange( TotalCount );
 
157
 
 
158
    int progress = 1;
 
159
    for ( int i=0; i<m_Manager.GetLibraryCount(); ++i )
 
160
    {
 
161
        const LibraryDetectionConfigSet* Set = m_Manager.GetLibrary(i);
 
162
        for ( size_t j=0; j<Set->Configurations.size(); ++j )
 
163
        {
 
164
            if ( StopFlag ) return false;
 
165
            Gauge1->SetValue( progress++ );
 
166
 
 
167
            ProcessLibrary( &Set->Configurations[j], Set );
 
168
        }
 
169
    }
 
170
 
 
171
    return !StopFlag;
 
172
}
 
173
 
 
174
bool ProcessingDlg::ProcessLibs( const wxArrayString& Shortcuts )
 
175
{
 
176
    int TotalCount = 0;
 
177
    for ( int i=0; i<m_Manager.GetLibraryCount(); ++i )
 
178
    {
 
179
        if ( const LibraryDetectionConfigSet* Set = m_Manager.GetLibrary( Shortcuts[i] ) )
 
180
        {
 
181
            TotalCount += (int)Set->Configurations.size();
 
182
        }
 
183
    }
 
184
    Gauge1->SetRange( TotalCount );
 
185
 
 
186
    int progress = 1;
 
187
    for ( size_t i=0; i<Shortcuts.Count(); ++i )
149
188
    {
150
189
        if ( StopFlag ) return false;
151
 
        ProcessLibrary(m_Manager.GetLibrary(i));
 
190
        Gauge1->SetValue( progress++ );
 
191
        if ( const LibraryDetectionConfigSet* Set = m_Manager.GetLibrary( Shortcuts[i] ) )
 
192
        {
 
193
            for ( size_t j=0; j<Set->Configurations.size(); ++j )
 
194
            {
 
195
                if ( StopFlag ) return false;
 
196
                Gauge1->SetValue( progress++ );
 
197
 
 
198
                ProcessLibrary( &Set->Configurations[j], Set );
 
199
            }
 
200
        }
152
201
    }
153
202
 
154
203
    return !StopFlag;
155
204
}
156
205
 
157
 
void ProcessingDlg::ProcessLibrary(const LibraryConfig* Config)
 
206
void ProcessingDlg::ApplyResults(bool addOnly)
 
207
{
 
208
    ResultArray Results;
 
209
    m_FoundResults.GetAllResults(Results);
 
210
    if ( Results.Count() == 0 )
 
211
    {
 
212
        cbMessageBox(_("Didn't found any library"));
 
213
        return;
 
214
    }
 
215
 
 
216
    wxArrayString Names;
 
217
    wxArrayInt Selected;
 
218
    wxString PreviousVar;
 
219
    for ( size_t i=0; i<Results.Count(); ++i )
 
220
    {
 
221
        wxString& Name =
 
222
            Results[i]->Description.IsEmpty() ?
 
223
            Results[i]->LibraryName :
 
224
            Results[i]->Description;
 
225
 
 
226
        Names.Add(
 
227
            wxString::Format(_T("%s : %s"),
 
228
                Results[i]->ShortCode.c_str(),
 
229
                Name.c_str()));
 
230
        if ( PreviousVar != Results[i]->ShortCode )
 
231
        {
 
232
            Selected.Add((int)i);
 
233
            PreviousVar = Results[i]->ShortCode;
 
234
        }
 
235
    }
 
236
 
 
237
    LibSelectDlg Dlg( this, Names, addOnly );
 
238
    Dlg.SetSelections( Selected );
 
239
 
 
240
    if ( Dlg.ShowModal() == wxID_OK )
 
241
    {
 
242
        // Fetch selected libraries
 
243
        Selected = Dlg.GetSelections();
 
244
 
 
245
        // Clear all results if requested
 
246
        if ( Dlg.GetClearAllPrevious() )
 
247
        {
 
248
            m_KnownResults[rtDetected].Clear();
 
249
        }
 
250
 
 
251
        // Here we will store names of libraries set-up so far
 
252
        // by checking entries we will be able to find out whether
 
253
        // we have to clear previous settings
 
254
        wxArrayString AddedLibraries;
 
255
 
 
256
        for ( size_t i = 0; i<Selected.Count(); i++ )
 
257
        {
 
258
            wxString Library = Results[Selected[i]]->ShortCode;
 
259
 
 
260
            if ( true )
 
261
            {
 
262
                // Here we set-up internal libraries configuration
 
263
                if ( Dlg.GetClearSelectedPrevious() )
 
264
                {
 
265
                    if ( AddedLibraries.Index(Library)==wxNOT_FOUND )
 
266
                    {
 
267
                        // Ok, have to delete previosu results since this is the first
 
268
                        // occurence of this library in new set
 
269
                        ResultArray& Previous = m_KnownResults[rtDetected].GetShortCode(Library);
 
270
                        for ( size_t j=0; j<Previous.Count(); j++ )
 
271
                        {
 
272
                            delete Previous[j];
 
273
                        }
 
274
                        Previous.Clear();
 
275
                    }
 
276
                    AddedLibraries.Add(Library);
 
277
                }
 
278
                else if ( Dlg.GetDontClearPrevious() )
 
279
                {
 
280
                    // Find and remove duplicates
 
281
                    ResultArray& Previous = m_KnownResults[rtDetected].GetShortCode(Library);
 
282
                    for ( size_t j=0; j<Previous.Count(); j++ )
 
283
                    {
 
284
                        if ( *Previous[j] == *Results[Selected[i]] )
 
285
                        {
 
286
                            delete Previous[j];
 
287
                            Previous.RemoveAt(j--);
 
288
                        }
 
289
                    }
 
290
                }
 
291
 
 
292
                // Add the result
 
293
                m_KnownResults[rtDetected].GetShortCode(Library).Add(new LibraryResult(*Results[Selected[i]]));
 
294
            }
 
295
 
 
296
            if ( Dlg.GetSetupGlobalVars() )
 
297
            {
 
298
                // Here we set-up global variables
 
299
                Results[Selected[i]]->SetGlobalVar();
 
300
            }
 
301
        }
 
302
    }
 
303
}
 
304
 
 
305
 
 
306
void ProcessingDlg::ProcessLibrary(const LibraryDetectionConfig* Config,const LibraryDetectionConfigSet* Set)
158
307
{
159
308
    Status->SetLabel(
160
309
        wxString::Format(
161
310
            _("Searching library \"%s\""),
162
 
            Config->ShortCode.c_str()));
 
311
            Set->ShortCode.c_str()));
163
312
 
164
 
    CheckFilter(_T(""),wxStringStringMap(),wxArrayString(),Config,0);
 
313
    CheckFilter(_T(""),wxStringStringMap(),wxArrayString(),Config,Set,0);
165
314
}
166
315
 
167
316
void ProcessingDlg::CheckFilter(
168
317
    const wxString& OldBasePath,
169
318
    const wxStringStringMap& OldVars,
170
319
    const wxArrayString& OldCompilers,
171
 
    const LibraryConfig* Config,
 
320
    const LibraryDetectionConfig* Config,
 
321
    const LibraryDetectionConfigSet* Set,
172
322
    int WhichFilter)
173
323
{
174
324
    if ( (int)Config->Filters.size() <= WhichFilter )
175
325
    {
176
 
        FoundLibrary(OldBasePath,OldVars,OldCompilers,Config);
 
326
        FoundLibrary(OldBasePath,OldVars,OldCompilers,Config,Set);
177
327
        return;
178
328
    }
179
329
 
180
 
    const LibraryFilter& Filter = Config->Filters[WhichFilter];
 
330
    const LibraryDetectionFilter& Filter = Config->Filters[WhichFilter];
181
331
 
182
332
    switch ( Filter.Type )
183
333
    {
184
 
        case LibraryFilter::File:
 
334
        case LibraryDetectionFilter::File:
185
335
        {
186
336
            // Split path
187
337
            wxArrayString Pattern;
242
392
                }
243
393
 
244
394
                // Ok, this filter matches, let's advance to next filet
245
 
                CheckFilter(BasePath,Vars,OldCompilers,Config,WhichFilter+1);
 
395
                CheckFilter(BasePath,Vars,OldCompilers,Config,Set,WhichFilter+1);
246
396
            }
247
397
            break;
248
398
        }
249
399
 
250
 
        case LibraryFilter::Platform:
 
400
        case LibraryDetectionFilter::Platform:
251
401
        {
252
402
            wxStringTokenizer Tokenizer(Filter.Value,_T("| \t"));
253
403
            bool IsPlatform = false;
339
489
 
340
490
            if ( IsPlatform )
341
491
            {
342
 
                CheckFilter(OldBasePath,OldVars,OldCompilers,Config,WhichFilter+1);
 
492
                CheckFilter(OldBasePath,OldVars,OldCompilers,Config,Set,WhichFilter+1);
343
493
            }
344
494
            break;
345
495
        }
346
496
 
347
 
        case LibraryFilter::Exec:
 
497
        case LibraryDetectionFilter::Exec:
348
498
        {
349
499
            bool IsExec = false;
350
500
            if ( wxIsAbsolutePath(Filter.Value) )
380
530
 
381
531
            if ( IsExec )
382
532
            {
383
 
                CheckFilter(OldBasePath,OldVars,OldCompilers,Config,WhichFilter+1);
 
533
                CheckFilter(OldBasePath,OldVars,OldCompilers,Config,Set,WhichFilter+1);
384
534
            }
385
535
            break;
386
536
        }
387
537
 
388
 
        case LibraryFilter::PkgConfig:
 
538
        case LibraryDetectionFilter::PkgConfig:
389
539
        {
390
540
            if ( m_KnownResults[rtPkgConfig].IsShortCode(Filter.Value) )
391
541
            {
392
 
                CheckFilter(OldBasePath,OldVars,OldCompilers,Config,WhichFilter+1);
 
542
                CheckFilter(OldBasePath,OldVars,OldCompilers,Config,Set,WhichFilter+1);
393
543
            }
394
544
            break;
395
545
        }
396
546
 
397
 
        case LibraryFilter::Compiler:
 
547
        case LibraryDetectionFilter::Compiler:
398
548
        {
399
549
            if ( OldCompilers.IsEmpty() )
400
550
            {
401
551
                // If this is the first compiler filter, let's build new list and continue
402
 
                CheckFilter(OldBasePath,OldVars,wxStringTokenize(Filter.Value,_T("| \t")),Config,WhichFilter+1);
 
552
                CheckFilter(OldBasePath,OldVars,wxStringTokenize(Filter.Value,_T("| \t")),Config,Set,WhichFilter+1);
403
553
            }
404
554
            else
405
555
            {
418
568
 
419
569
                if ( !Compilers.IsEmpty() )
420
570
                {
421
 
                    CheckFilter(OldBasePath,OldVars,Compilers,Config,WhichFilter+1);
 
571
                    CheckFilter(OldBasePath,OldVars,Compilers,Config,Set,WhichFilter+1);
422
572
                }
423
573
            }
424
574
            break;
425
575
        }
426
576
 
427
 
        case LibraryFilter::None:
 
577
        case LibraryDetectionFilter::None:
428
578
        {
429
 
            CheckFilter(OldBasePath,OldVars,OldCompilers,Config,WhichFilter+1);
 
579
            CheckFilter(OldBasePath,OldVars,OldCompilers,Config,Set,WhichFilter+1);
430
580
            break;
431
581
        }
432
582
    }
448
598
    return true;
449
599
}
450
600
 
451
 
void ProcessingDlg::FoundLibrary(const wxString& OldBasePath,const wxStringStringMap& OldVars,const wxArrayString& Compilers,const LibraryConfig* Config)
 
601
void ProcessingDlg::FoundLibrary(const wxString& OldBasePath,const wxStringStringMap& OldVars,const wxArrayString& Compilers,const LibraryDetectionConfig* Config,const LibraryDetectionConfigSet* Set)
452
602
{
453
603
    wxStringStringMap Vars = OldVars;
454
604
    wxString BasePath = OldBasePath;
458
608
    LibraryResult* Result = new LibraryResult();
459
609
 
460
610
    Result->Type = rtDetected;
461
 
    Result->ShortCode = Config->ShortCode;
462
 
    Result->LibraryName = FixVars(Config->LibraryName,Vars);
 
611
    Result->ShortCode = Set->ShortCode;
 
612
    Result->LibraryName = FixVars(Set->LibraryName,Vars);
463
613
    Result->BasePath = FixPath(BasePath);
464
614
    Result->PkgConfigVar = Config->PkgConfigVar;
465
615
    Result->Description = FixVars(Config->Description,Vars);
466
616
 
467
617
    Result->Compilers = Compilers;
468
 
    Result->Categories = Config->Categories;
 
618
    Result->Categories = Set->Categories;
469
619
 
470
620
    for ( size_t i=0; i<Config->IncludePaths.Count(); i++ )
471
621
    {
502
652
        Result->LFlags.Add(FixVars(Config->LFlags[i],Vars));
503
653
    }
504
654
 
505
 
    ResultArray& Array = m_FoundResults.GetShortCode(Config->ShortCode);
 
655
    Result->Headers = Config->Headers;
 
656
    Result->Require = Config->Require;
 
657
 
 
658
    ResultArray& Array = m_FoundResults.GetShortCode(Set->ShortCode);
506
659
    Array.Add(Result);
507
660
}
508
661