1 --- fpicker/source/unx/kde/kdefilepicker.hxx 2005-03-03 15:38:55.741091637 +0100
2 +++ fpicker/source/unx/kde/kdefilepicker.hxx 2005-03-04 16:23:10.215148048 +0100
3 @@ -96,6 +96,7 @@ protected:
4 * (custom list boxes are under this check box, which looks ugly).
9 bool m_bCanNotifySelection;
11 @@ -125,6 +126,12 @@ protected:
12 void setIsSave( bool bIsSave ) { m_bIsSave = bIsSave; }
13 bool isSave( void ) const { return m_bIsSave; }
15 + void setIsExecuting( bool bIsExecuting ) { m_bIsExecuting = bIsExecuting; }
16 + bool isExecuting( void ) const { return m_bIsExecuting; }
18 + bool isSupportedProtocol( const QString &rProtocol ) const;
19 + QString localCopy( const QString &rFileName ) const;
21 void setCanNotifySelection( bool bCanNotifySelection ) { m_bCanNotifySelection = bCanNotifySelection; }
22 bool canNotifySelection( void ) const { return m_bCanNotifySelection; }
24 --- fpicker/source/unx/kde/kdefilepicker.cxx 2005-03-03 15:38:50.737956764 +0100
25 +++ fpicker/source/unx/kde/kdefilepicker.cxx 2005-03-04 16:39:33.815625995 +0100
27 #include <kdiroperator.h>
28 #include <kfiledialog.h>
29 #include <kfilefiltercombo.h>
30 +#include <kio/netaccess.h>
32 #include <kmessagebox.h>
33 +#include <ktempfile.h>
37 @@ -98,6 +100,7 @@ FileDialog::FileDialog( const QString &s
38 m_pPushButtons( new QVBox( m_pCombosAndButtons ) ),
39 m_pCheckBoxes( new QGrid( 2, m_pCustomWidget ) ),
41 + m_bIsExecuting( false ),
42 m_bCanNotifySelection( true )
44 connect( this, SIGNAL( fileHighlighted( const QString & ) ),
45 @@ -257,10 +260,16 @@ void FileDialog::customEvent( QCustomEve
46 for ( KURL::List::const_iterator it = qList.begin(); it != qList.end(); ++it )
48 qString.append( " " );
49 - QString qUrlStr = (*it).url();
50 + QString qUrlStr = addExtension( (*it).url() );
52 + if ( !isExecuting() && !isSupportedProtocol( KURL( qUrlStr ).protocol() ) )
53 + qUrlStr = localCopy( qUrlStr );
55 if ( qUrlStr.startsWith( "file:/" ) && qUrlStr.mid( 6, 1 ) != "/" )
56 qUrlStr.replace( "file:/", "file:///" );
57 - appendEscaped( qString, addExtension( qUrlStr ) );
59 + if ( !qUrlStr.isEmpty() )
60 + appendEscaped( qString, qUrlStr );
64 @@ -270,10 +279,16 @@ void FileDialog::customEvent( QCustomEve
65 for ( KFileItemListIterator it( *pItems ); it.current(); ++it )
67 qString.append( " " );
68 - QString qUrlStr = (*it)->url().url();
69 + QString qUrlStr = addExtension( (*it)->url().url() );
71 + if ( !isExecuting() && !isSupportedProtocol( KURL( qUrlStr ).protocol() ) )
72 + qUrlStr = localCopy( qUrlStr );
74 if ( qUrlStr.startsWith( "file:/" ) && qUrlStr.mid( 6, 1 ) != "/" )
75 qUrlStr.replace( "file:/", "file:///" );
76 - appendEscaped( qString, addExtension( qUrlStr ) );
78 + if ( !qUrlStr.isEmpty() )
79 + appendEscaped( qString, qUrlStr );
83 @@ -322,18 +337,47 @@ void FileDialog::customEvent( QCustomEve
85 filterWidget->setEditable( false );
87 + setIsExecuting( true );
88 + bool bCanExit = false;
90 setCanNotifySelection( true );
93 qSelectedURL = addExtension( selectedURL().url() );
94 - } while ( isSave() &&
95 - result() == QDialog::Accepted &&
96 - ( qSelectedURL.startsWith( "file:" ) && QFile::exists( qSelectedURL.mid( 5 ) ) ) &&
97 - KMessageBox::warningYesNo( 0,
98 - i18n( "A file named \"%1\" already exists. "
99 - "Are you sure you want to overwrite it?" ).arg( qSelectedURL ),
100 - i18n( "Overwrite File?" ),
101 - i18n( "Overwrite" ), KStdGuiItem::cancel() ) != KMessageBox::Yes );
102 + QString qProtocol( selectedURL().protocol() );
104 + if ( isSave() && result() == QDialog::Accepted )
106 + if ( qSelectedURL.startsWith( "file:" ) )
109 + !QFile::exists( qSelectedURL.mid( 5 ) ) ||
110 + ( KMessageBox::warningYesNo( 0,
111 + i18n( "A file named \"%1\" already exists. "
112 + "Are you sure you want to overwrite it?" ).arg( qSelectedURL ),
113 + i18n( "Overwrite File?" ),
114 + i18n( "Overwrite" ), KStdGuiItem::cancel() ) == KMessageBox::Yes );
116 + else if ( !isSupportedProtocol( qProtocol ) )
118 + KMessageBox::sorry( 0,
119 + i18n( "Saving using protocol \"%1\" is not supported." ).arg( qProtocol ) );
125 + else if ( !isSave() && result() == QDialog::Accepted && !isSupportedProtocol( qProtocol ) )
127 + KMessageBox::information( 0,
128 + i18n( "Protocol \"%1\" is supported only partially. "
129 + "Local copy of the file will be created." ).arg( qProtocol ) );
134 + } while ( !bCanExit );
135 + setIsExecuting( false );
137 if ( result() == QDialog::Accepted )
138 sendCommand( "accept" );
139 @@ -563,6 +607,50 @@ QString FileDialog::addExtension( const
140 return rFileName + qExtension;
143 +bool FileDialog::isSupportedProtocol( const QString &rProtocol ) const
145 + // TODO Get this information directly from OOo
146 + const char * pOOoProtocols[] = { "", "smb", "ftp", "http", "file", "mailto",
147 + "vnd.sun.star.webdav", "news", "private", "vnd.sun.star.help",
148 + "https", "slot", "macro", "javascript", "imap", "pop3", "data",
149 + "cid", "out", "vnd.sun.star.wfs", "vnd.sun.star.hier", "vim",
150 + ".uno", ".component", "vnd.sun.star.pkg", "ldap", "db",
151 + "vnd.sun.star.cmd", "vnd.sun.star.script", "vnd.sun.star.odma",
155 + for ( const char **pIndex = pOOoProtocols; *pIndex != NULL; ++pIndex )
157 + if ( rProtocol == *pIndex )
161 + // TODO gnome-vfs bits here
166 +QString FileDialog::localCopy( const QString &rFileName ) const
168 + int nExtensionPos = rFileName.findRev( '/' );
169 + if ( nExtensionPos >= 0 )
170 + nExtensionPos = rFileName.find( '.', nExtensionPos );
172 + nExtensionPos = rFileName.find( '.' );
174 + KTempFile qTempFile( QString::null, ( nExtensionPos < 0 )? QString(): rFileName.mid( nExtensionPos ) );
176 + qDestURL.setPath( qTempFile.name() );
178 + if ( !KIO::NetAccess::file_copy( rFileName, qDestURL, 0600, true, false, NULL ) )
180 + KMessageBox::error( 0, KIO::NetAccess::lastErrorString() );
181 + return QString::null;
184 + return qDestURL.url();
187 void FileDialog::fileHighlightedCommand( const QString & )
189 if ( canNotifySelection() )