summaryrefslogtreecommitdiffstats
path: root/kpovmodeler/pmfiledialog.cpp
blob: d8da0f4d2c61e7f48f1850f0b5c4c194ebce487b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
**************************************************************************
                                 description
                             --------------------
    copyright            : (C) 2003 by Andreas Zehender
    email                : zehender@kde.org
**************************************************************************

**************************************************************************
*                                                                        *
*  This program is free software; you can redistribute it and/or modify  *
*  it under the terms of the GNU General Public License as published by  *
*  the Free Software Foundation; either version 2 of the License, or     *
*  (at your option) any later version.                                   *
*                                                                        *
**************************************************************************/


#include "pmfiledialog.h"
#include "pmpart.h"

#include <kfilefiltercombo.h>


PMFileDialog::PMFileDialog( const TQString& startDir, const TQString& filter, TQWidget* parent, const char* name, bool modal )
      : KFileDialog( startDir, filter, parent, name, modal )
{

}

TQString PMFileDialog::getImportFileName( TQWidget* parent, PMPart* part,
                                         PMIOFormat*& format )
{
   PMIOManager* manager = part->ioManager( );
   TQString filter;
   TQPtrListIterator<PMIOFormat> it( manager->formats( ) );
   TQPtrList<PMIOFormat> formats;

   for( ; it.current( ); ++it )
   {
      if( it.current( )->services( ) & PMIOFormat::Import )
      {
         TQStringList patterns = it.current( )->importPatterns( );
         TQStringList::Iterator pit;
         for( pit = patterns.begin( ); pit != patterns.end( ); ++pit )
         {
            if( !filter.isEmpty( ) )
               filter += "\n";
            filter += *pit;
            formats.append( it.current( ) );
         }
      }
   }

   PMFileDialog dlg( TQString::null, filter, parent, "import file dialog", true );
   dlg.setOperationMode( Opening );
   dlg.setMode( KFile::File | KFile::LocalOnly );
   dlg.setCaption( i18n( "Import" ) );
   dlg.filterWidget->setEditable( false );
   dlg.exec( );

   format = formats.at( dlg.filterWidget->currentItem( ) );

   return dlg.selectedFile( );
}

TQString PMFileDialog::getExportFileName( TQWidget* parent, PMPart* part,
                                         PMIOFormat*& format, TQString& selectedFilter )
{
   PMIOManager* manager = part->ioManager( );
   TQString filter;
   TQPtrListIterator<PMIOFormat> it( manager->formats( ) );
   TQPtrList<PMIOFormat> formats;

   for( ; it.current( ); ++it )
   {
      if( it.current( )->services( ) & PMIOFormat::Export )
      {
         TQStringList patterns = it.current( )->exportPatterns( );
         TQStringList::Iterator pit;
         for( pit = patterns.begin( ); pit != patterns.end( ); ++pit )
         {
            if( !filter.isEmpty( ) )
               filter += "\n";
            filter += *pit;
            formats.append( it.current( ) );
         }
      }
   }

   PMFileDialog dlg( TQString::null, filter, parent, "export file dialog", true );
   dlg.setOperationMode( Saving );
   dlg.setMode( KFile::File | KFile::LocalOnly );
   dlg.setCaption( i18n( "Export" ) );
   dlg.filterWidget->setEditable( false );
   dlg.exec( );

   format = formats.at( dlg.filterWidget->currentItem( ) );
   selectedFilter = dlg.currentFilter( );

   return dlg.selectedFile( );
}

#include "pmfiledialog.moc"