20 #include "pastedialog.h"
22 #include "tdeio/job.h"
23 #include "tdeio/global.h"
24 #include "tdeio/netaccess.h"
25 #include "tdeio/observer.h"
26 #include "tdeio/renamedlg.h"
27 #include "tdeio/tdeprotocolmanager.h"
32 #include <tdelocale.h>
33 #include <kinputdialog.h>
34 #include <tdemessagebox.h>
35 #include <kmimetype.h>
36 #include <tdetempfile.h>
38 #include <tqapplication.h>
39 #include <tqclipboard.h>
40 #include <tqdragobject.h>
41 #include <tqtextstream.h>
42 #include <tqvaluevector.h>
44 static KURL getNewFileName(
const KURL &u,
const TQString& text )
47 TQString dialogText( text );
48 if ( dialogText.isEmpty() )
49 dialogText = i18n(
"Filename for clipboard content:" );
50 TQString file = KInputDialog::getText( TQString::null, dialogText, TQString::null, &ok );
55 myurl.addPath( file );
59 kdDebug(7007) <<
"Paste will overwrite file. Prompting..." << endl;
65 0L, i18n(
"File Already Exists"),
68 (TDEIO::RenameDlg_Mode) (TDEIO::M_OVERWRITE | TDEIO::M_SINGLE), newPath);
70 if ( res == TDEIO::R_RENAME )
74 else if ( res == TDEIO::R_CANCEL )
84 static TDEIO::CopyJob* pasteDataAsyncTo(
const KURL& new_url,
const TQByteArray& _data )
87 tempFile.dataStream()->writeRawBytes( _data.data(), _data.size() );
91 orig_url.setPath(tempFile.name());
96 #ifndef TQT_NO_MIMECLIPBOARD
97 static TDEIO::CopyJob* chooseAndPaste(
const KURL& u, TQMimeSource* data,
98 const TQValueVector<TQCString>& formats,
103 TQStringList formatLabels;
104 for ( uint i = 0; i < formats.size(); ++i ) {
105 const TQCString& fmt = formats[i];
108 formatLabels.append( i18n(
"%1 (%2)" ).arg( mime->comment() ).arg( fmt.data() ) );
110 formatLabels.append( fmt );
113 TQString dialogText( text );
114 if ( dialogText.isEmpty() )
115 dialogText = i18n(
"Filename for clipboard content:" );
116 TDEIO::PasteDialog dlg( TQString::null, dialogText, TQString::null, formatLabels, widget, clipboard );
118 if ( dlg.exec() != KDialogBase::Accepted )
121 if ( clipboard && dlg.clipboardChanged() ) {
122 KMessageBox::sorry( widget,
123 i18n(
"The clipboard has changed since you used 'paste': "
124 "the chosen data format is no longer applicable. "
125 "Please copy again what you wanted to paste." ) );
129 const TQString result = dlg.lineEditText();
130 const TQCString chosenFormat = formats[ dlg.comboItem() ];
132 kdDebug() <<
" result=" << result <<
" chosenFormat=" << chosenFormat << endl;
134 new_url.addPath( result );
138 data = TQApplication::clipboard()->data();
140 const TQByteArray ba = data->encodedData( chosenFormat );
141 return pasteDataAsyncTo( new_url, ba );
148 #ifndef TQT_NO_MIMECLIPBOARD
149 TQMimeSource *data = TQApplication::clipboard()->data();
150 if ( data->provides(
"text/uri-list" ) && data->encodedData(
"text/uri-list" ).size() > 0 )
155 TQString data = TQApplication::clipboard()->text();
156 if(data.contains(
"://"))
162 #ifndef TQT_NO_MIMECLIPBOARD
165 const TQString& dialogText, TQWidget* widget,
bool clipboard )
172 if ( TQTextDrag::canDecode( data ) && TQTextDrag::decode( data, text ) )
174 TQTextStream txtStream( ba, IO_WriteOnly );
179 TQValueVector<TQCString> formats;
181 for (
int i = 0; ( fmt = data->format( i ) ); ++i ) {
182 if ( qstrcmp( fmt,
"application/x-qiconlist" ) == 0 )
184 if ( qstrcmp( fmt,
"application/x-tde-cutselection" ) == 0 )
186 if ( strchr( fmt,
'/' ) == 0 )
188 formats.append( fmt );
191 if ( formats.size() == 0 )
194 if ( formats.size() > 1 ) {
195 return chooseAndPaste( dest_url, data, formats, dialogText, widget, clipboard );
197 ba = data->encodedData( formats.first() );
199 if ( ba.size() == 0 )
201 KMessageBox::sorry(0, i18n(
"The clipboard is empty"));
212 if ( !dest_url.isValid() ) {
213 KMessageBox::error( 0L, i18n(
"Malformed URL\n%1" ).arg( dest_url.url() ) );
217 #ifndef TQT_NO_MIMECLIPBOARD
218 TQMimeSource *data = TQApplication::clipboard()->data();
222 if ( KURLDrag::canDecode( data ) && KURLDrag::decode( data, urls ) ) {
223 if ( urls.count() == 0 ) {
224 KMessageBox::error( 0L, i18n(
"The clipboard is empty"));
236 TQApplication::clipboard()->clear();
242 TQTextStream txtStream( ba, IO_WriteOnly );
243 TQStringList data = TQStringList::split(
"\n", TQApplication::clipboard()->text());
245 KURLDrag::decode(data, urls);
246 TQStringList::Iterator end(data.end());
247 for(TQStringList::Iterator it=data.begin(); it!=end; ++it)
249 if ( ba.size() == 0 )
251 KMessageBox::sorry(0, i18n(
"The clipboard is empty"));
261 KURL new_url = getNewFileName( u, TQString::null );
265 if (new_url.isEmpty())
269 tempFile.setAutoDelete(
true );
270 tempFile.dataStream()->writeRawBytes( _data.data(), _data.size() );
283 KURL new_url = getNewFileName( u, text );
285 if (new_url.isEmpty())
288 return pasteDataAsyncTo( new_url, _data );
293 TQMimeSource *data = TQApplication::clipboard()->data();
295 if ( KURLDrag::canDecode( data ) && KURLDrag::decode( data, urls ) ) {
296 if ( urls.isEmpty() )
297 return TQString::null;
298 else if ( urls.first().isLocalFile() )
299 return i18n(
"&Paste File",
"&Paste %n Files", urls.count() );
301 return i18n(
"&Paste URL",
"&Paste %n URLs", urls.count() );
302 }
else if ( data->format(0) != 0 ) {
303 return i18n(
"&Paste Clipboard Contents" );
305 return TQString::null;
static KMimeType::Ptr defaultMimeTypePtr()
Returns the default mimetype.
static Ptr mimeType(const TQString &_name)
Retrieve a pointer to the mime type _name or a pointer to the default mime type "application/octet-st...
static Observer * self()
Returns the unique observer object.
CopyJob is used to move, copy or symlink files and directories.
The base class for all jobs.
static bool exists(const KURL &url, bool source, TQWidget *window)
Tests whether a URL exists.
static bool upload(const TQString &src, const KURL &target, TQWidget *window)
Uploads file src to URL target.
TDEIO_EXPORT CopyJob * move(const KURL &src, const KURL &dest, bool showProgressInfo=true)
Moves a file or directory src to the given destination dest.
TDEIO_EXPORT TQString pasteActionText()
Returns the text to use for the Paste action, when the application supports pasting files,...
TDEIO_EXPORT CopyJob * pasteMimeSource(TQMimeSource *data, const KURL &destURL, const TQString &dialogText, TQWidget *widget, bool clipboard=false)
Save the given mimesource data to the given destination URL after offering the user to choose a data ...
TDEIO_EXPORT_DEPRECATED bool isClipboardEmpty()
Checks whether the clipboard contains any URLs.
TDEIO_EXPORT CopyJob * pasteDataAsync(const KURL &destURL, const TQByteArray &data)
Pastes the given data to the given destination URL.
TDEIO_EXPORT void pasteData(const KURL &destURL, const TQByteArray &data)
Pastes the given data to the given destination URL.
TDEIO_EXPORT CopyJob * copy(const KURL &src, const KURL &dest, bool showProgressInfo=true)
Copy a file or directory src into the destination dest, which can be a file (including the final file...
TDEIO_EXPORT Job * pasteClipboard(const KURL &destURL, bool move=false)
Pastes the content of the clipboard to the given destination URL.
RenameDlg_Result
The result of open_RenameDlg().