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>
32#include <tqtextstream.h>
33#include <tqfileinfo.h>
35#include <tdeinstance.h>
37#include <tdetempfile.h>
38#include <tdemessagebox.h>
40#include <kstandarddirs.h>
41#include <tdefiledialog.h>
42#include <kdirnotify_stub.h>
49template class TQPtrList<KXMLGUIClient>;
51using namespace KParts;
86 d =
new PartBasePrivate;
100TQObject *PartBase::partObject()
const
130 d->m_pluginLoadingMode = loadingMode;
134 : TQObject( parent, name )
149 disconnect( m_widget, TQ_SIGNAL( destroyed() ),
150 this, TQ_SLOT( slotWidgetDestroyed() ) );
154 m_manager->removePart(
this);
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, TQ_SIGNAL( destroyed() ),
199 this, TQ_SLOT( slotWidgetDestroyed() ) );
213 d->m_bSelectable = selectable;
218 return d->m_bSelectable;
221void Part::customEvent( TQCustomEvent *event )
223 if ( PartActivateEvent::test( event ) )
229 if ( PartSelectEvent::test( event ) )
235 if ( GUIActivateEvent::test( event ) )
241 TQObject::customEvent( event );
264void Part::slotWidgetDestroyed()
266 kdDebug(1000) <<
"KPart::slotWidgetDestroyed(), deleting part " << name() <<
endl;
276class 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;
307 d =
new ReadOnlyPartPrivate;
318 d->m_showProgressInfo = show;
323 return d->m_showProgressInfo;
327void ReadOnlyPart::showProgressInfo(
bool show )
329 d->m_showProgressInfo = show;
335 if ( !
url.isValid() )
340 if (
m_url.isLocalFile() )
356 TQString fileName =
url.fileName();
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, TQ_SIGNAL( result( TDEIO::Job * ) ),
this, TQ_SLOT( slotJobFinished ( TDEIO::Job * ) ) );
375void ReadOnlyPart::abortLoad()
391 unlink( TQFile::encodeName(
m_file) );
400void 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())
419 if (!
m_url.isEmpty())
421 kdDebug(1000) <<
"ReadOnlyPart::guiActivateEvent -> " <<
m_url.prettyURL() <<
endl;
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 ),
494 i18n(
"Close Document" ), KStdGuiItem::save(), KStdGuiItem::discard() );
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;
582void ReadWritePart::prepareSaving()
589 unlink( TQFile::encodeName(
m_file) );
609 if (
m_url.isLocalFile() )
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, TQ_SIGNAL( result( TDEIO::Job * ) ),
this, TQ_SLOT( slotUploadFinished (TDEIO::Job *) ) );
647void 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*");
663 KURL dirUrl(
m_url );
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)
682void tqt_enter_modal( TQWidget *widget );
683void tqt_leave_modal( TQWidget *widget );
690 d->m_waitForSave =
true;
692 TQWidget dummy(0,0,(WFlags)(WType_Dialog | WShowModal));
693 dummy.setFocusPolicy( TQWidget::NoFocus );
694 tqt_enter_modal(&dummy);
696 tqt_leave_modal(&dummy);
698 d->m_waitForSave =
false;
static int warningYesNoCancel(TQWidget *parent, const TQString &text, const TQString &caption=TQString::null, const KGuiItem &buttonYes=KStdGuiItem::yes(), const KGuiItem &buttonNo=KStdGuiItem::no(), const TQString &dontAskAgainName=TQString::null, int options=Notify)
This event is sent to a Part when its GUI has been activated or deactivated.
This event is sent by the part manager when the active part changes.
void loadPlugins(TQObject *parent, KXMLGUIClient *parentGUIClient, TDEInstance *instance)
Load the Plugins honoring the PluginLoadingMode.
void setPluginLoadingMode(PluginLoadingMode loadingMode)
For a KParts::Part: call this before setInstance().
virtual void setInstance(TDEInstance *instance)
Set the instance ( TDEInstance) for this part.
PluginLoadingMode
We have three different policies, whether to load new plugins or not.
@ DoNotLoadPlugins
Don't load any plugins at all.
@ LoadPlugins
Load new plugins automatically.
virtual ~PartBase()
Destructor.
void setPartObject(TQObject *object)
Internal method.
The part manager is an object which knows about a collection of parts (even nested ones) and handles ...
This event is sent when a part is selected or deselected.
virtual ~Part()
Destructor.
void setWindowCaption(const TQString &caption)
Emitted by the part, to set the caption of the window(s) hosting this part.
virtual void partSelectEvent(PartSelectEvent *event)
Convenience method which is called when the Part received a PartSelectEvent .
Part(TQObject *parent=0, const char *name=0)
Constructor.
bool isSelectable() const
Returns whether the part is selectable or not.
virtual void embed(TQWidget *parentWidget)
Embed this part into a host widget.
virtual void setWidget(TQWidget *widget)
Set the main widget.
virtual void setSelectable(bool selectable)
virtual void guiActivateEvent(GUIActivateEvent *event)
Convenience method which is called when the Part received a GUIActivateEvent .
virtual void partActivateEvent(PartActivateEvent *event)
Convenience method which is called when the Part received a PartActivateEvent .
virtual TQWidget * widget()
TQWidget * hostContainer(const TQString &containerName)
Convenience method for KXMLGUIFactory::container.
PartManager * manager() const
Returns the part manager handling this part, if any (0L otherwise).
virtual Part * hitTest(TQWidget *widget, const TQPoint &globalPos)
Returns the part (this, or a child part) at the given global position.
static void loadPlugins(TQObject *parent, const TDEInstance *instance)
Load the plugin libraries from the directories appropriate to instance and make the Plugin objects ch...
bool isProgressInfoEnabled() const
Returns whether the part shows the progress info dialog used by internal TDEIO job.
virtual bool openURL(const KURL &url)
Only reimplement openURL if you don't want the network transparency support to download from the url ...
ReadOnlyPart(TQObject *parent=0, const char *name=0)
Constructor See also Part for the setXXX methods to call.
void setProgressInfoEnabled(bool show)
Call this to turn off the progress info dialog used by the internal TDEIO job.
bool writeStream(const TQByteArray &data)
Send some data to the part.
bool m_bTemp
If true, m_file is a temporary file that needs to be deleted later.
void canceled(const TQString &errMsg)
Emit this if loading is canceled by the user or by an error.
virtual void guiActivateEvent(GUIActivateEvent *event)
Reimplemented from Part, so that the window caption is set to the current url (decoded) when the part...
void completed()
Emit this when you have completed loading data.
TQString m_file
Local file - the only one the part implementation should deal with.
virtual ~ReadOnlyPart()
Destructor.
bool closeStream()
Terminate the sending of data to the part.
KURL m_url
Remote (or local) url - the one displayed to the user.
bool openStream(const TQString &mimeType, const KURL &url)
Initiate sending data to this part.
virtual bool closeURL()
Called when closing the current url (e.g.
void started(TDEIO::Job *)
The part emits this when starting data.
virtual bool openFile()=0
If the part uses the standard implementation of openURL(), it must reimplement this,...
KURL url() const
Returns the currently in part used URL.
virtual void setReadWrite(bool readwrite=true)
Changes the behavior of this part to readonly or readwrite.
virtual bool saveAs(const KURL &url)
Save the file to a new location.
virtual bool saveToURL()
Save the file.
ReadWritePart(TQObject *parent=0, const char *name=0)
Constructor.
bool queryClose()
If the document has been modified, ask the user to save changes.
virtual bool closeURL()
Called when closing the current url (e.g.
virtual bool saveFile()=0
Save to a local file.
bool waitSaveComplete()
Waits for any pending upload job to finish and returns whether the last save() action was successful.
virtual bool save()
Save the file in the location from which it was opened.
virtual ~ReadWritePart()
Destructor.
void sigQueryClose(bool *handled, bool *abortClosing)
virtual void setModified()
Call setModified() whenever the contents get modified.
void setPath(const TQString &path)
TQString fileName(bool _ignore_trailing_slash_in_path=true) const
TQString url(int _trailing=0, int encoding_hint=0) const
TQString prettyURL(int _trailing=0) const
virtual TDEInstance * instance() const
KXMLGUIFactory * factory() const
virtual TDEActionCollection * actionCollection() const
virtual void setInstance(TDEInstance *instance)
TQWidget * container(const TQString &containerName, KXMLGUIClient *client, bool useTagName=false)
virtual void setWidget(TQWidget *widget)
void setAutoConnectShortcuts(bool)
static TDEStandardDirs * dirs()
static TDELocale * locale()
TQCString instanceName() const
void insertCatalogue(const TQString &catalog)
bool addResourceType(const char *type, const TQString &relativename)
static TQString kde_default(const char *type)
kdbgstream kdError(int area=0)
kndbgstream & endl(kndbgstream &s)
kdbgstream kdDebug(int area=0)