20 #include "kmfactory.h"
21 #include "kmmanager.h"
22 #include "kmjobmanager.h"
23 #include "kmuimanager.h"
24 #include "kprinterimpl.h"
26 #include "kpreloadobject.h"
27 #include "tdeprintcheck.h"
28 #include "kxmlcommand.h"
32 #include <tqsettings.h>
34 #include <klibloader.h>
35 #include <tdeconfig.h>
36 #include <kstandarddirs.h>
37 #include <kiconloader.h>
39 #include <tdemessagebox.h>
40 #include <tdelocale.h>
41 #include <ksimpleconfig.h>
42 #include <kstaticdeleter.h>
43 #include <tdeapplication.h>
44 #include <dcopclient.h>
46 #include <tdeio/authinfo.h>
50 #define UNLOAD_OBJECT(x) if (x != 0) { delete x; x = 0; }
53 extern void tqt_generate_epsf(
bool b );
56 KMFactory* KMFactory::m_self = 0;
57 static KStaticDeleter<KMFactory> s_kmfactorysd;
59 KMFactory* KMFactory::self()
62 m_self = s_kmfactorysd.setObject(m_self,
new KMFactory());
66 bool KMFactory::exists()
71 void KMFactory::release()
75 KMFactory* p = m_self;
81 KMFactory::KMFactory()
82 : TQObject(NULL,
"Factory")
84 m_settings =
new Settings;
85 m_settings->application = KPrinter::Dialog;
86 m_settings->pageSelection = KPrinter::SystemSide;
87 m_settings->standardDialogPages = KPrinter::CopiesPage;
88 m_settings->pageSize = -1;
89 m_settings->orientation = -1;
91 m_objects.setAutoDelete(
false);
99 #if TQT_VERSION >= 230
105 tqt_generate_epsf(
false );
112 settings.readBoolEntry(
"/qt/embedFonts",
true, &ok );
114 settings.writeEntry(
"/qt/embedFonts",
true );
116 TDEGlobal::iconLoader()->addAppDir(
"tdeprint");
117 TDEGlobal::locale()->insertCatalogue(
"tdeprint");
120 connectDCOPSignal(0, 0,
"pluginChanged(pid_t)",
"slot_pluginChanged(pid_t)",
false);
121 connectDCOPSignal(0, 0,
"configChanged()",
"slot_configChanged()",
false);
124 KMFactory::~KMFactory()
129 UNLOAD_OBJECT(m_printconfig);
133 KMManager* KMFactory::manager()
137 TQ_CHECK_PTR(m_manager);
141 KMJobManager* KMFactory::jobManager()
145 TQ_CHECK_PTR(m_jobmanager);
149 KMUiManager* KMFactory::uiManager()
153 TQ_CHECK_PTR(m_uimanager);
157 KPrinterImpl* KMFactory::printerImplementation()
159 if (!m_implementation)
161 TQ_CHECK_PTR(m_implementation);
162 return m_implementation;
165 KMVirtualManager* KMFactory::virtualManager()
167 return manager()->m_virtualmgr;
170 KMSpecialManager* KMFactory::specialManager()
172 return manager()->m_specialmgr;
175 KXmlCommandManager* KMFactory::commandManager()
177 return KXmlCommandManager::self();
180 void KMFactory::createManager()
183 if (m_factory) m_manager = (KMManager*)m_factory->create(
this,
"Manager",
"KMManager");
184 if (!m_manager) m_manager =
new KMManager(
this,
"Manager");
187 void KMFactory::createJobManager()
190 if (m_factory) m_jobmanager = (KMJobManager*)m_factory->create(
this,
"JobManager",
"KMJobManager");
191 if (!m_jobmanager) m_jobmanager =
new KMJobManager(
this,
"JobManager");
194 void KMFactory::createUiManager()
197 if (m_factory) m_uimanager = (KMUiManager*)m_factory->create(
this,
"UiManager",
"KMUiManager");
198 if (!m_uimanager) m_uimanager =
new KMUiManager(
this,
"UiManager");
201 void KMFactory::createPrinterImpl()
204 if (m_factory) m_implementation = (KPrinterImpl*)m_factory->create(
this,
"PrinterImpl",
"KPrinterImpl");
205 if (!m_implementation) m_implementation =
new KPrinterImpl(
this,
"PrinterImpl");
208 void KMFactory::loadFactory(
const TQString& syst)
216 TQString libname = TQString::fromLatin1(
"tdeprint_%1").arg(sys);
217 m_factory = KLibLoader::self()->factory(TQFile::encodeName(libname));
220 KMessageBox::error(0,
221 i18n(
"<qt>There was an error loading %1. The diagnostic is:<p>%2</p></qt>")
222 .arg(libname).arg(KLibLoader::self()->lastErrorMessage()));
227 TDEConfig* KMFactory::printConfig(
const TQString& group)
231 m_printconfig =
new TDEConfig(
"tdeprintrc");
232 TQ_CHECK_PTR(m_printconfig);
234 if (!group.isEmpty())
235 m_printconfig->setGroup(group);
236 return m_printconfig;
239 TQString KMFactory::printSystem()
241 TDEConfig *conf = printConfig();
242 conf->setGroup(
"General");
243 TQString sys = conf->readEntry(
"PrintSystem");
249 conf->writeEntry(
"PrintSystem", sys);
252 else if ( sys.length()==1 && sys[0].isDigit() )
257 void KMFactory::unload()
259 UNLOAD_OBJECT(m_manager);
260 UNLOAD_OBJECT(m_jobmanager);
261 UNLOAD_OBJECT(m_uimanager);
262 UNLOAD_OBJECT(m_implementation);
268 void KMFactory::reload(
const TQString& syst,
bool saveSyst)
271 TQPtrListIterator<KPReloadObject> it(m_objects);
272 for (;it.current();++it)
273 it.current()->aboutToReload();
279 TDEConfig *conf = printConfig();
280 conf->setGroup(
"General");
281 conf->writeEntry(
"PrintSystem", syst);
285 emit pluginChanged(getpid());
292 for (it.toFirst();it.current();++it)
293 it.current()->reload();
296 TQValueList<KMFactory::PluginInfo> KMFactory::pluginList()
298 TQDir d(locate(
"data",
"tdeprint/plugins/"),
"*.print", TQDir::Name, TQDir::Files);
299 TQValueList<PluginInfo> list;
300 for (uint i=0; i<d.count(); i++)
302 PluginInfo info(pluginInfo(d.absFilePath(d[i])));
303 if (info.name.isEmpty())
310 KMFactory::PluginInfo KMFactory::pluginInfo(
const TQString& name)
314 path = locate(
"data", TQString::fromLatin1(
"tdeprint/plugins/%1.print").arg(name));
315 KSimpleConfig conf(path);
318 conf.setGroup(
"TDE Print Entry");
319 info.name = conf.readEntry(
"PrintSystem");
320 info.comment = conf.readEntry(
"Comment");
321 if (info.comment.isEmpty())
322 info.comment = info.name;
323 info.detectUris = conf.readListEntry(
"DetectUris");
324 info.detectPrecedence = conf.readNumEntry(
"DetectPrecedence", 0);
325 info.mimeTypes = conf.readListEntry(
"MimeTypes");
326 if (info.mimeTypes.isEmpty())
327 info.mimeTypes <<
"application/postscript";
328 info.primaryMimeType = conf.readEntry(
"PrimaryMimeType", info.mimeTypes[0]);
333 void KMFactory::registerObject(KPReloadObject *obj,
bool priority)
336 if (m_objects.findRef(obj) == -1)
339 m_objects.prepend(obj);
341 m_objects.append(obj);
342 kdDebug(500) <<
"tdeprint: registering " << (
void*)obj <<
", number of objects = " << m_objects.count() << endl;
346 void KMFactory::unregisterObject(KPReloadObject *obj)
349 m_objects.removeRef(obj);
350 kdDebug(500) <<
"tdeprint: unregistering " << (
void*)obj <<
", number of objects = " << m_objects.count() << endl;
353 TQString KMFactory::autoDetect()
355 TQValueList<PluginInfo> plugins = pluginList();
356 int pluginIndex(-1), currentPrecedence(0);
357 for (uint i=0;i<plugins.count();i++)
359 if (plugins[i].detectUris.count() > 0 && KdeprintChecker::check(plugins[i].detectUris)
360 && (pluginIndex == -1 || plugins[i].detectPrecedence >= currentPrecedence))
363 currentPrecedence = plugins[i].detectPrecedence;
366 return (pluginIndex == -1 ? TQString::fromLatin1(
"lpdunix") : plugins[pluginIndex].name);
369 void KMFactory::slot_pluginChanged(pid_t pid)
375 printConfig()->rollback();
376 UNLOAD_OBJECT(m_printconfig);
379 TQString syst = printSystem();
384 void KMFactory::slot_configChanged()
386 kdDebug(500) <<
"KMFactory (" << getpid() <<
") receiving DCOP signal configChanged()" << endl;
390 printConfig()->rollback();
391 UNLOAD_OBJECT(m_printconfig);
395 TQPtrListIterator<KPReloadObject> it(m_objects);
400 for (it.toFirst(); it.current();++it)
401 it.current()->configChanged();
404 void KMFactory::saveConfig()
406 TDEConfig *conf = printConfig();
408 kdDebug(500) <<
"KMFactory (" << getpid() <<
") emitting DCOP signal configChanged()" << endl;
409 emit configChanged();
415 TQPair<TQString,TQString> KMFactory::requestPassword(
int& seqNbr,
const TQString& user,
const TQString& host,
int port )
417 DCOPRef tdeprintd(
"kded",
"tdeprintd" );
424 DCOPReply reply = tdeprintd.call(
"requestPassword", user, host, port, seqNbr );
425 if ( reply.isValid() )
427 TQString replyString = reply;
428 if ( replyString !=
"::" )
430 TQStringList l = TQStringList::split(
':', replyString,
true );
431 if ( l.count() == 3 )
433 seqNbr = l[ 2 ].toInt();
434 return TQPair<TQString,TQString>( l[ 0 ], l[ 1 ] );
438 return TQPair<TQString,TQString>( TQString::null, TQString::null );
441 void KMFactory::initPassword(
const TQString& user,
const TQString& password,
const TQString& host,
int port )
443 DCOPRef tdeprintd(
"kded",
"tdeprintd" );
450 tdeprintd.call(
"initPassword", user, password, host, port );
453 #include "kmfactory.moc"