21 #include <tdeparts/part.h>
22 #include <tdeparts/event.h>
23 #include <tdeparts/plugin.h>
24 #include <tdeparts/mainwindow.h>
25 #include <tdeparts/partmanager.h>
27 #include <tqapplication.h>
30 #include <tqpointarray.h>
31 #include <tqpainter.h>
32 #include <tqtextstream.h>
33 #include <tqfileinfo.h>
35 #include <kinstance.h>
37 #include <tdetempfile.h>
38 #include <tdemessagebox.h>
39 #include <tdeio/job.h>
40 #include <kstandarddirs.h>
41 #include <tdefiledialog.h>
42 #include <kdirnotify_stub.h>
49 template class TQPtrList<KXMLGUIClient>;
51 using namespace KParts;
86 d =
new PartBasePrivate;
100 TQObject *PartBase::partObject()
const
130 d->m_pluginLoadingMode = loadingMode;
134 : TQObject( parent, name )
149 disconnect( m_widget, TQT_SIGNAL( destroyed() ),
150 this, TQT_SLOT( slotWidgetDestroyed() ) );
158 kdDebug(1000) <<
"deleting widget " << m_widget <<
" " << m_widget->name() <<
endl;
159 delete (TQWidget*) m_widget;
168 widget()->reparent( parentWidget, 0, TQPoint( 0, 0 ),
true );
188 if ( (TQWidget *)m_widget != widget )
196 assert ( !m_widget );
198 connect( m_widget, TQT_SIGNAL( destroyed() ),
199 this, TQT_SLOT( slotWidgetDestroyed() ) );
213 d->m_bSelectable = selectable;
218 return d->m_bSelectable;
221 void Part::customEvent( TQCustomEvent *event )
223 if ( PartActivateEvent::test( event ) )
229 if ( PartSelectEvent::test( event ) )
235 if ( GUIActivateEvent::test( event ) )
241 TQObject::customEvent( event );
264 void Part::slotWidgetDestroyed()
266 kdDebug(1000) <<
"KPart::slotWidgetDestroyed(), deleting part " << name() <<
endl;
276 class ReadOnlyPartPrivate
279 ReadOnlyPartPrivate()
283 m_showProgressInfo =
true;
285 m_waitForSave =
false;
286 m_duringSaveAs =
false;
288 ~ReadOnlyPartPrivate()
292 TDEIO::FileCopyJob * m_job;
293 TDEIO::FileCopyJob * m_uploadJob;
295 TQString m_originalFilePath;
296 bool m_showProgressInfo : 1;
298 bool m_waitForSave : 1;
299 bool m_duringSaveAs : 1;
305 :
Part( parent, name ), m_bTemp( false )
307 d =
new ReadOnlyPartPrivate;
318 d->m_showProgressInfo = show;
323 return d->m_showProgressInfo;
326 #ifndef KDE_NO_COMPAT
327 void ReadOnlyPart::showProgressInfo(
bool show )
329 d->m_showProgressInfo = show;
357 TQFileInfo fileInfo(fileName);
358 TQString ext = fileInfo.extension();
360 if ( !ext.isEmpty() && url.
query().isNull() )
362 KTempFile tempFile( TQString::null, extension );
367 d->m_job = TDEIO::file_copy(
m_url, destURL, 0600,
true,
false, d->m_showProgressInfo );
368 d->m_job->setWindow(
widget() ?
widget()->topLevelWidget() : 0 );
370 connect( d->m_job, TQT_SIGNAL( result( TDEIO::Job * ) ),
this, TQT_SLOT( slotJobFinished ( TDEIO::Job * ) ) );
375 void ReadOnlyPart::abortLoad()
391 unlink( TQFile::encodeName(
m_file) );
400 void ReadOnlyPart::slotJobFinished( TDEIO::Job * job )
402 kdDebug(1000) <<
"ReadOnlyPart::slotJobFinished" <<
endl;
403 assert( job == d->m_job );
406 emit
canceled( job->errorString() );
417 if (event->activated())
432 return doOpenStream( mimeType );
437 return doWriteStream( data );
442 return doCloseStream();
448 :
ReadOnlyPart( parent, name ), m_bModified( false ), m_bClosing( false )
464 m_bReadWrite = readwrite;
469 kdDebug(1000) <<
"ReadWritePart::setModified( " << (modified ?
"true" :
"false") <<
")" <<
endl;
470 if ( !m_bReadWrite && modified )
472 kdError(1000) <<
"Can't set a read-only document to 'modified' !" <<
endl;
475 m_bModified = modified;
489 if (docName.isEmpty()) docName = i18n(
"Untitled" );
492 i18n(
"The document \"%1\" has been modified.\n"
493 "Do you want to save your changes or discard them?" ).arg( docName ),
496 bool abortClose=
false;
500 case KMessageBox::Yes :
506 KURL url = KFileDialog::getSaveURL();
516 }
else if (abortClose)
return false;
518 case KMessageBox::No :
561 d->m_duringSaveAs =
true;
562 d->m_originalURL =
m_url;
563 d->m_originalFilePath =
m_file;
566 bool result =
save();
571 m_url = d->m_originalURL;
572 m_file = d->m_originalFilePath;
573 d->m_duringSaveAs =
false;
574 d->m_originalURL =
KURL();
575 d->m_originalFilePath = TQString::null;
582 void ReadWritePart::prepareSaving()
589 unlink( TQFile::encodeName(
m_file) );
616 d->m_duringSaveAs =
false;
617 d->m_originalURL =
KURL();
618 d->m_originalFilePath = TQString::null;
625 unlink(TQFile::encodeName(d->m_uploadJob->srcURL().path()));
626 d->m_uploadJob->kill();
630 TQString uploadFile = tempFile.
name();
632 uploadUrl.
setPath( uploadFile );
635 if (::link(TQFile::encodeName(
m_file), TQFile::encodeName(uploadFile)) != 0)
640 d->m_uploadJob = TDEIO::file_move( uploadUrl,
m_url, -1,
true );
641 d->m_uploadJob->setWindow(
widget() ?
widget()->topLevelWidget() : 0 );
642 connect( d->m_uploadJob, TQT_SIGNAL( result( TDEIO::Job * ) ),
this, TQT_SLOT( slotUploadFinished (TDEIO::Job *) ) );
647 void ReadWritePart::slotUploadFinished( TDEIO::Job * )
649 if (d->m_uploadJob->error())
651 unlink(TQFile::encodeName(d->m_uploadJob->srcURL().path()));
652 TQString error = d->m_uploadJob->errorString();
654 if (d->m_duringSaveAs) {
655 m_url = d->m_originalURL;
656 m_file = d->m_originalFilePath;
662 KDirNotify_stub allDirNotify(
"*",
"KDirNotify*");
664 dirUrl.setPath( dirUrl.directory() );
665 allDirNotify.FilesAdded( dirUrl );
672 d->m_duringSaveAs =
false;
673 d->m_originalURL =
KURL();
674 d->m_originalFilePath = TQString::null;
675 if (d->m_waitForSave)
682 void tqt_enter_modal( TQWidget *widget );
683 void tqt_leave_modal( TQWidget *widget );
690 d->m_waitForSave =
true;
692 TQWidget dummy(0,0,(WFlags)(WType_Dialog | WShowModal));
693 dummy.setFocusPolicy( TQ_NoFocus );
694 tqt_enter_modal(&dummy);
696 tqt_leave_modal(&dummy);
698 d->m_waitForSave =
false;