2 #include "kgraphinterface_part.h"
6 #include <kstdaction.h>
7 #include <kfiledialog.h>
12 #include <qtextstream.h>
15 #include "gihandler.h"
17 KGraphInterfacePart::KGraphInterfacePart( QWidget
*parentWidget
, const char *widgetName
,
18 QObject
*parent
, const char *name
)
19 : KParts::ReadWritePart(parent
, name
)
21 // we need an instance
22 setInstance( KGraphInterfacePartFactory::instance() );
24 // this should be your custom internal widget
25 m_widget
= new Graph( parentWidget
, "Graphe" );
27 // notify the part that this is our internal widget
31 KStdAction::open(this, SLOT(fileOpen()), actionCollection());
32 KStdAction::saveAs(this, SLOT(fileSaveAs()), actionCollection());
33 KStdAction::save(this, SLOT(save()), actionCollection());
35 // set our XML-UI resource file
36 setXMLFile("kgraphinterface_part.rc");
38 // we are read-write by default
41 // we are not modified since we haven't done anything yet
45 KGraphInterfacePart::~KGraphInterfacePart()
49 void KGraphInterfacePart::setReadWrite(bool rw
)
51 // notify your internal widget of the read-write state
52 /* m_widget->setReadOnly(!rw);
54 connect(m_widget, SIGNAL(textChanged()),
55 this, SLOT(setModified()));
58 disconnect(m_widget, SIGNAL(textChanged()),
59 this, SLOT(setModified()));
62 ReadWritePart::setReadWrite(rw
);
65 void KGraphInterfacePart::setModified(bool modified
)
67 // get a handle on our Save action and make sure it is valid
68 KAction
*save
= actionCollection()->action(KStdAction::stdName(KStdAction::Save
));
72 // if so, we either enable or disable it based on the current
75 save
->setEnabled(true);
77 save
->setEnabled(false);
79 // in any event, we want our parent to do it's thing
80 ReadWritePart::setModified(modified
);
83 bool KGraphInterfacePart::openFile()
85 // m_file is always local so we can use QFile on it
87 if (file
.open(IO_ReadOnly
) == false)
90 //On parse le fichier recu
91 GIHandler
handler (m_widget
);
92 QXmlSimpleReader reader
;
93 reader
.setContentHandler(&handler
);
94 reader
.setErrorHandler(&handler
);
95 QXmlInputSource
source(&file
);
100 // now that we have the entire file, display it
101 // m_widget->setText(str);
103 // just for fun, set the status bar
104 emit
setStatusBarText( m_url
.prettyURL() );
109 bool KGraphInterfacePart::saveFile()
111 // if we aren't read-write, return immediately
112 if (isReadWrite() == false)
115 // m_file is always local, so we use QFile
117 if (file
.open(IO_WriteOnly
) == false)
120 // use QTextStream to dump the text to the file
121 QTextStream
stream(&file
);
122 stream
<< m_widget
->toXml();
129 void KGraphInterfacePart::fileOpen()
131 // this slot is called whenever the File->Open menu is selected,
132 // the Open shortcut is pressed (usually CTRL+O) or the Open toolbar
134 QString file_name
= KFileDialog::getOpenFileName();
136 if (file_name
.isEmpty() == false)
140 void KGraphInterfacePart::fileSaveAs()
142 // this slot is called whenever the File->Save As menu is selected,
143 QString file_name
= KFileDialog::getSaveFileName();
144 if (file_name
.isEmpty() == false)
149 // It's usually safe to leave the factory code alone.. with the
150 // notable exception of the KAboutData data
151 #include <kaboutdata.h>
154 KInstance
* KGraphInterfacePartFactory::s_instance
= 0L;
155 KAboutData
* KGraphInterfacePartFactory::s_about
= 0L;
157 KGraphInterfacePartFactory::KGraphInterfacePartFactory()
162 KGraphInterfacePartFactory::~KGraphInterfacePartFactory()
170 KParts::Part
* KGraphInterfacePartFactory::createPartObject( QWidget
*parentWidget
, const char *widgetName
,
171 QObject
*parent
, const char *name
,
172 const char *classname
, const QStringList
&args
)
174 // Create an instance of our Part
175 KGraphInterfacePart
* obj
= new KGraphInterfacePart( parentWidget
, widgetName
, parent
, name
);
177 // See if we are to be read-write or not
178 if (QCString(classname
) == "KParts::ReadOnlyPart")
179 obj
->setReadWrite(false);
184 KInstance
* KGraphInterfacePartFactory::instance()
188 s_about
= new KAboutData("kgraphinterfacepart", I18N_NOOP("KGraphInterfacePart"), "0.1");
189 s_about
->addAuthor("Schpilka Yannick", 0, "schpilka@gmail.com");
190 s_instance
= new KInstance(s_about
);
197 void* init_libkgraphinterfacepart()
199 KGlobal::locale()->insertCatalogue("kgraphinterface");
200 return new KGraphInterfacePartFactory
;
204 #include "kgraphinterface_part.moc"