Smb4K – Samba (SMB) share advanced browser
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

956 lines
24KB

  1. /***************************************************************************
  2. smb4kcore - The main core class of Smb4K.
  3. -------------------
  4. begin : Do Apr 8 2004
  5. copyright : (C) 2004-2007 by Alexander Reinholdt
  6. email : dustpuppy@users.berlios.de
  7. ***************************************************************************/
  8. /***************************************************************************
  9. * This program is free software; you can redistribute it and/or modify *
  10. * it under the terms of the GNU General Public License as published by *
  11. * the Free Software Foundation; either version 2 of the License, or *
  12. * (at your option) any later version. *
  13. * *
  14. * This program is distributed in the hope that it will be useful, but *
  15. * WITHOUT ANY WARRANTY; without even the implied warranty of *
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
  17. * General Public License for more details. *
  18. * *
  19. * You should have received a copy of the GNU General Public License *
  20. * along with this program; if not, write to the *
  21. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, *
  22. * MA 02110-1301 USA *
  23. ***************************************************************************/
  24. // TQt includes
  25. #include <tqdir.h>
  26. #include <tqmap.h>
  27. #include <tqstringlist.h>
  28. // KDE includes
  29. #include <tdeversion.h>
  30. #include <tdelocale.h>
  31. #include <tdemessagebox.h>
  32. #include <kurl.h>
  33. #include <krun.h>
  34. #include <tdeapplication.h>
  35. #include <kpassivepopup.h>
  36. #include <kdebug.h>
  37. #include <kstaticdeleter.h>
  38. #include <dcopclient.h>
  39. // system includes
  40. #include <stdlib.h>
  41. // application specific includes
  42. #include "smb4kcore.h"
  43. #include "smb4kdefs.h"
  44. #include "smb4kerror.h"
  45. #include "smb4tdeglobal.h"
  46. #include "smb4knetworkitems.h"
  47. #include "smb4kshare.h"
  48. #include "smb4ksambaoptionshandler.h"
  49. #include "smb4ksettings.h"
  50. using namespace Smb4TDEGlobal;
  51. Smb4KCore *Smb4KCore::m_self = 0;
  52. static KStaticDeleter<Smb4KCore> staticSmb4KCoreDeleter;
  53. Smb4KCore::Smb4KCore() : TQObject()
  54. {
  55. // Set default values for settings that depend on the system
  56. // Smb4K is running on:
  57. setDefaultSettings();
  58. // Search for the programs that are needed by Smb4K:
  59. searchPrograms();
  60. m_fileIO = new Smb4KFileIO( this, "CoreFileIO" );
  61. m_scanner = new Smb4KScanner( &m_workgroups, &m_hosts, this, "CoreScanner" );
  62. m_mounter = new Smb4KMounter( this, "CoreMounter" );
  63. m_bookmarkHandler = new Smb4KBookmarkHandler( &m_hosts, this, "CoreBookmarkHandler" );
  64. m_print = new Smb4KPrint( this, "CorePrinterHandler" );
  65. m_synchronizer = new Smb4KSynchronizer( this, "CoreSynchronizer" );
  66. m_previewer = new Smb4KPreviewer( this, "CorePreviewer" );
  67. m_scanner_state = SCANNER_STOP;
  68. m_mounter_state = MOUNTER_STOP;
  69. m_print_state = PRINT_STOP;
  70. m_syncer_state = SYNCHRONIZER_STOP;
  71. m_previewer_state = PREVIEWER_STOP;
  72. // Connections:
  73. connect( m_scanner, TQT_SIGNAL( state( int ) ),
  74. this, TQT_SLOT( slotSetScannerState( int ) ) );
  75. connect( m_mounter, TQT_SIGNAL( state( int ) ),
  76. this, TQT_SLOT( slotSetMounterState( int ) ) );
  77. connect( m_print, TQT_SIGNAL( state( int ) ),
  78. this, TQT_SLOT( slotSetPrinterHandlerState( int ) ) );
  79. connect( m_synchronizer, TQT_SIGNAL( state( int ) ),
  80. this, TQT_SLOT( slotSetSynchronizerState( int ) ) );
  81. connect( m_previewer, TQT_SIGNAL( state( int ) ),
  82. this, TQT_SLOT( slotSetSynchronizerState( int ) ) );
  83. connect( kapp, TQT_SIGNAL( shutDown() ),
  84. this, TQT_SLOT( slotShutdown() ) );
  85. }
  86. Smb4KCore::~Smb4KCore()
  87. {
  88. // Do not call abort() here. This will most likely lead
  89. // to crashes.
  90. // Clear the list of workgroups.
  91. for ( TQValueList<Smb4KWorkgroupItem *>::Iterator it = m_workgroups.begin(); it != m_workgroups.end(); ++it )
  92. {
  93. delete *it;
  94. }
  95. m_workgroups.clear();
  96. // Clear the list of hosts.
  97. for ( TQValueList<Smb4KHostItem *>::Iterator it = m_hosts.begin(); it != m_hosts.end(); ++it )
  98. {
  99. delete *it;
  100. }
  101. m_hosts.clear();
  102. if ( m_self == this )
  103. {
  104. staticSmb4KCoreDeleter.setObject( m_self, 0, false );
  105. }
  106. }
  107. Smb4KCore *Smb4KCore::self()
  108. {
  109. if ( !m_self )
  110. {
  111. staticSmb4KCoreDeleter.setObject( m_self, new Smb4KCore() );
  112. }
  113. return m_self;
  114. }
  115. void Smb4KCore::init()
  116. {
  117. // Start the core.
  118. m_scanner->init();
  119. m_mounter->init();
  120. }
  121. /****************************************************************************
  122. Returns a bool that tells the program whether a core process is running.
  123. ****************************************************************************/
  124. bool Smb4KCore::isRunning()
  125. {
  126. if ( self()->m_scanner->isRunning() || self()->m_mounter->isRunning() ||
  127. self()->m_print->isRunning() || self()->m_synchronizer->isRunning() ||
  128. self()->m_previewer->isRunning() )
  129. {
  130. return true;
  131. }
  132. else
  133. {
  134. return false;
  135. }
  136. }
  137. /****************************************************************************
  138. Sets the current state of the core.
  139. ****************************************************************************/
  140. void Smb4KCore::setCurrentState( int state )
  141. {
  142. if ( state != SCANNER_STOP && state != MOUNTER_STOP &&
  143. state != PRINT_STOP && state != SYNCHRONIZER_STOP &&
  144. state != PREVIEWER_STOP )
  145. {
  146. m_current_state = state;
  147. }
  148. else
  149. {
  150. if ( !m_scanner->isRunning() && !m_mounter->isRunning() &&
  151. !m_print->isRunning() && !m_synchronizer->isRunning() &&
  152. !m_previewer->isRunning() )
  153. {
  154. m_current_state = CORE_STOP;
  155. }
  156. else
  157. {
  158. if ( m_scanner->isRunning() )
  159. {
  160. m_current_state = m_scanner_state;
  161. }
  162. else if ( m_print->isRunning() )
  163. {
  164. m_current_state = m_print_state;
  165. }
  166. else if ( m_mounter->isRunning() )
  167. {
  168. m_current_state = m_mounter_state;
  169. }
  170. else if ( m_synchronizer->isRunning() )
  171. {
  172. m_current_state = m_syncer_state;
  173. }
  174. else if ( m_previewer->isRunning() )
  175. {
  176. m_current_state = m_previewer_state;
  177. }
  178. }
  179. }
  180. }
  181. /****************************************************************************
  182. Aborts any process of the core.
  183. ****************************************************************************/
  184. void Smb4KCore::abort()
  185. {
  186. self()->m_scanner->abort();
  187. self()->m_mounter->abort();
  188. self()->m_print->abort();
  189. self()->m_synchronizer->abort();
  190. self()->m_previewer->abort();
  191. }
  192. /****************************************************************************
  193. Opens the given URL.
  194. ****************************************************************************/
  195. void Smb4KCore::open( Smb4KShare *share, int openWith )
  196. {
  197. if ( !share || share->isBroken() )
  198. {
  199. return;
  200. }
  201. #if TDE_VERSION_MAJOR == 3 && TDE_VERSION_MINOR <= 3 && TDE_VERSION_RELEASE <= 92
  202. if ( TQString::compare( share->filesystem(), "cifs" ) == 0 )
  203. {
  204. if( KMessageBox::warningContinueCancel( (TQWidget *)this, i18n( "Up to KDE 3.3.x, TDEIO and Konqueror cannot handle CIFS shares. Konqueror will hang if you try to access it.\nDo you want to continue?" ) ) == KMessageBox::Cancel )
  205. {
  206. return;
  207. }
  208. }
  209. #endif
  210. switch ( openWith )
  211. {
  212. case Konqueror:
  213. {
  214. KURL url;
  215. url.setPath( share->canonicalPath() );
  216. (void) new KRun( url, 0, true, true );
  217. break;
  218. }
  219. case Konsole:
  220. {
  221. if ( Smb4KSettings::konsole().isEmpty() )
  222. {
  223. Smb4KError::error( ERROR_COMMAND_NOT_FOUND, "konsole" );
  224. }
  225. else
  226. {
  227. KRun::runCommand( "konsole --workdir "+share->canonicalPath() );
  228. }
  229. break;
  230. }
  231. default:
  232. {
  233. break;
  234. }
  235. }
  236. }
  237. /****************************************************************************
  238. Searches for the programs needed by Smb4K
  239. ****************************************************************************/
  240. void Smb4KCore::searchPrograms()
  241. {
  242. // Remove the group "Programs" and reread the
  243. // configuration:
  244. Smb4KSettings::self()->config()->deleteGroup( "Programs" );
  245. Smb4KSettings::self()->readConfig();
  246. // List of paths that should be searched.
  247. TQStringList path_list = TQStringList::split( ":", TQString( "%1" ).arg( getenv( "PATH" ) ), false );
  248. if ( path_list.find( "/sbin" ) == path_list.end() )
  249. {
  250. path_list << "/sbin";
  251. }
  252. if ( path_list.find( "/usr/sbin" ) == path_list.end() )
  253. {
  254. path_list << "/usr/sbin";
  255. }
  256. if ( path_list.find( "/usr/local/sbin" ) == path_list.end() )
  257. {
  258. path_list << "/usr/local/sbin";
  259. }
  260. // Put all programs that are needed by Smb4K
  261. // into the map below:
  262. TQMap<TQString /*name*/, bool /*located*/> program_list;
  263. TQMap<TQString /*name*/, TQString /*absolute path*/> program_paths;
  264. // Mandatory programs:
  265. program_list.insert( "grep", false );
  266. program_list.insert( "awk", false );
  267. program_list.insert( "sed", false );
  268. program_list.insert( "xargs", false );
  269. program_list.insert( "rmdir", false );
  270. program_list.insert( "nmblookup", false );
  271. program_list.insert( "smbclient", false );
  272. program_list.insert( "smbspool", false );
  273. program_list.insert( "net", false );
  274. #ifndef __FreeBSD__
  275. program_list.insert( "mount.cifs", false );
  276. program_list.insert( "umount.cifs", false );
  277. program_list.insert( "smbmount", false );
  278. program_list.insert( "smbumount", false );
  279. program_list.insert( "mount", false );
  280. #else
  281. program_list.insert( "mount_smbfs", false );
  282. program_list.insert( "smbutil", false );
  283. #endif
  284. program_list.insert( "umount", false );
  285. program_list.insert( "smb4k_mount", false );
  286. program_list.insert( "smb4k_umount", false );
  287. program_list.insert( "smb4k_kill", false );
  288. program_list.insert( "smb4k_cat", false );
  289. program_list.insert( "smb4k_mv", false );
  290. // Optional programs
  291. program_list.insert( "super", false );
  292. program_list.insert( "sudo", false );
  293. program_list.insert( "dvips", false );
  294. program_list.insert( "enscript", false );
  295. program_list.insert( "rsync", false );
  296. program_list.insert( "konsole", false );
  297. for ( TQStringList::ConstIterator it = path_list.begin(); it != path_list.end(); ++it )
  298. {
  299. TQDir::setCurrent( *it );
  300. for ( TQMap<TQString, bool>::Iterator p = program_list.begin(); p != program_list.end(); ++p )
  301. {
  302. if ( p.data() == false ) // not located yet
  303. {
  304. if ( TQFile::exists( p.key() ) )
  305. {
  306. program_paths.insert( p.key(), TQDir::currentDirPath()+TQDir::separator()+p.key() );
  307. program_list[ p.key() ] = true;
  308. }
  309. else
  310. {
  311. continue;
  312. }
  313. }
  314. else
  315. {
  316. continue;
  317. }
  318. }
  319. }
  320. // Find out if Smb4K is to be starting up at all:
  321. TQStringList missing;
  322. if ( !program_list["grep"] )
  323. {
  324. missing.append( "grep" );
  325. }
  326. else
  327. {
  328. Smb4KSettings::self()->grepItem()->setDefaultValue( program_paths["grep"] );
  329. if ( Smb4KSettings::grep().isEmpty() )
  330. {
  331. Smb4KSettings::self()->grepItem()->setDefault();
  332. }
  333. }
  334. if ( !program_list["awk"] )
  335. {
  336. missing.append( "awk" );
  337. }
  338. else
  339. {
  340. Smb4KSettings::self()->awkItem()->setDefaultValue( program_paths["awk"] );
  341. if ( Smb4KSettings::awk().isEmpty() )
  342. {
  343. Smb4KSettings::self()->awkItem()->setDefault();
  344. }
  345. }
  346. if ( !program_list["sed"] )
  347. {
  348. missing.append( "sed" );
  349. }
  350. else
  351. {
  352. Smb4KSettings::self()->sedItem()->setDefaultValue( program_paths["sed"] );
  353. if ( Smb4KSettings::sed().isEmpty() )
  354. {
  355. Smb4KSettings::self()->sedItem()->setDefault();
  356. }
  357. }
  358. if ( !program_list["xargs"] )
  359. {
  360. missing.append( "xargs" );
  361. }
  362. else
  363. {
  364. Smb4KSettings::self()->xargsItem()->setDefaultValue( program_paths["xargs"] );
  365. if ( Smb4KSettings::xargs().isEmpty() )
  366. {
  367. Smb4KSettings::self()->xargsItem()->setDefault();
  368. }
  369. }
  370. if ( !program_list["rmdir"] )
  371. {
  372. missing.append( "rmdir" );
  373. }
  374. else
  375. {
  376. Smb4KSettings::self()->rmdirItem()->setDefaultValue( program_paths["rmdir"] );
  377. if ( Smb4KSettings::rmdir().isEmpty() )
  378. {
  379. Smb4KSettings::self()->rmdirItem()->setDefault();
  380. }
  381. }
  382. if ( !program_list["nmblookup"] )
  383. {
  384. missing.append( "nmblookup" );
  385. }
  386. else
  387. {
  388. Smb4KSettings::self()->nmblookupItem()->setDefaultValue( program_paths["nmblookup"] );
  389. if ( Smb4KSettings::nmblookup().isEmpty() )
  390. {
  391. Smb4KSettings::self()->nmblookupItem()->setDefault();
  392. }
  393. }
  394. if ( !program_list["smbclient"] )
  395. {
  396. missing.append( "smbclient" );
  397. }
  398. else
  399. {
  400. Smb4KSettings::self()->smbclientItem()->setDefaultValue( program_paths["smbclient"] );
  401. if ( Smb4KSettings::smbclient().isEmpty() )
  402. {
  403. Smb4KSettings::self()->smbclientItem()->setDefault();
  404. }
  405. }
  406. if ( !program_list["smbspool"] )
  407. {
  408. missing.append( "smbspool" );
  409. }
  410. else
  411. {
  412. Smb4KSettings::self()->smbspoolItem()->setDefaultValue( program_paths["smbspool"] );
  413. if ( Smb4KSettings::smbspool().isEmpty() )
  414. {
  415. Smb4KSettings::self()->smbspoolItem()->setDefault();
  416. }
  417. }
  418. if ( !program_list["net"] )
  419. {
  420. missing.append( "net" );
  421. }
  422. else
  423. {
  424. Smb4KSettings::self()->netItem()->setDefaultValue( program_paths["net"] );
  425. if ( Smb4KSettings::net().isEmpty() )
  426. {
  427. Smb4KSettings::self()->netItem()->setDefault();
  428. }
  429. }
  430. #ifndef __FreeBSD__
  431. if ( !program_list["mount.cifs"] && !program_list["smbmount"] )
  432. {
  433. missing.append( "mount.cifs & smbmount" );
  434. }
  435. else
  436. {
  437. // One of the two programs is at least present, so we can do
  438. // it like this:
  439. TQString filesystem;
  440. if ( program_list["mount.cifs"] )
  441. {
  442. Smb4KSettings::self()->mount_cifsItem()->setDefaultValue( program_paths["mount.cifs"] );
  443. if ( Smb4KSettings::mount_cifs().isEmpty() )
  444. {
  445. Smb4KSettings::self()->mount_cifsItem()->setDefault();
  446. }
  447. }
  448. else
  449. {
  450. Smb4KSettings::setFilesystem( Smb4KSettings::EnumFilesystem::SMBFS );
  451. }
  452. if ( program_list["smbmount"] )
  453. {
  454. Smb4KSettings::self()->smbmountItem()->setDefaultValue( program_paths["smbmount"] );
  455. if ( Smb4KSettings::smbmount().isEmpty() )
  456. {
  457. Smb4KSettings::self()->smbmountItem()->setDefault();
  458. }
  459. }
  460. else
  461. {
  462. Smb4KSettings::setFilesystem( Smb4KSettings::EnumFilesystem::CIFS );
  463. }
  464. }
  465. if ( !program_list["umount.cifs"] && !program_list["smbumount"] )
  466. {
  467. missing.append( "umount.cifs & smbumount" );
  468. }
  469. else
  470. {
  471. // One of the two programs is at least present, so we can do
  472. // it like this:
  473. TQString filesystem;
  474. if ( program_list["umount.cifs"] )
  475. {
  476. Smb4KSettings::self()->umount_cifsItem()->setDefaultValue( program_paths["umount.cifs"] );
  477. if ( Smb4KSettings::umount_cifs().isEmpty() )
  478. {
  479. Smb4KSettings::self()->umount_cifsItem()->setDefault();
  480. }
  481. }
  482. else
  483. {
  484. Smb4KSettings::setFilesystem( Smb4KSettings::EnumFilesystem::SMBFS );
  485. }
  486. if ( program_list["smbumount"] )
  487. {
  488. Smb4KSettings::self()->smbumountItem()->setDefaultValue( program_paths["smbumount"] );
  489. if ( Smb4KSettings::smbumount().isEmpty() )
  490. {
  491. Smb4KSettings::self()->smbumountItem()->setDefault();
  492. }
  493. }
  494. else
  495. {
  496. Smb4KSettings::setFilesystem( Smb4KSettings::EnumFilesystem::CIFS );
  497. }
  498. }
  499. if ( !program_list["mount"] )
  500. {
  501. missing.append( "mount" );
  502. }
  503. else
  504. {
  505. Smb4KSettings::self()->mountItem()->setDefaultValue( program_paths["mount"] );
  506. if ( Smb4KSettings::mount().isEmpty() )
  507. {
  508. Smb4KSettings::self()->mountItem()->setDefault();
  509. }
  510. }
  511. #else
  512. if ( !program_list["mount_smbfs"] )
  513. {
  514. missing.append( "mount_smbfs" );
  515. }
  516. else
  517. {
  518. Smb4KSettings::self()->mount_smbfsItem()->setDefaultValue( program_paths["mount_smbfs"] );
  519. if ( Smb4KSettings::mount_smbfs().isEmpty() )
  520. {
  521. Smb4KSettings::self()->mount_smbfsItem()->setDefault();
  522. }
  523. }
  524. if ( !program_list["smbutil"] )
  525. {
  526. missing.append( "smbutil" );
  527. }
  528. else
  529. {
  530. Smb4KSettings::self()->smbutilItem()->setDefaultValue( program_paths["smbutil"] );
  531. if ( Smb4KSettings::smbutil().isEmpty() )
  532. {
  533. Smb4KSettings::self()->smbutilItem()->setDefault();
  534. }
  535. }
  536. #endif
  537. if ( !program_list["umount"] )
  538. {
  539. missing.append( "umount" );
  540. }
  541. else
  542. {
  543. Smb4KSettings::self()->umountItem()->setDefaultValue( program_paths["umount"] );
  544. if ( Smb4KSettings::umount().isEmpty() )
  545. {
  546. Smb4KSettings::self()->umountItem()->setDefault();
  547. }
  548. }
  549. if ( !program_list["smb4k_mount"] )
  550. {
  551. missing.append( "smb4k_mount" );
  552. }
  553. else
  554. {
  555. Smb4KSettings::self()->smb4k_mountItem()->setDefaultValue( program_paths["smb4k_mount"] );
  556. if ( Smb4KSettings::smb4k_mount().isEmpty() )
  557. {
  558. Smb4KSettings::self()->smb4k_mountItem()->setDefault();
  559. }
  560. }
  561. if ( !program_list["smb4k_umount"] )
  562. {
  563. missing.append( "smb4k_umount" );
  564. }
  565. else
  566. {
  567. Smb4KSettings::self()->smb4k_umountItem()->setDefaultValue( program_paths["smb4k_umount"] );
  568. if ( Smb4KSettings::smb4k_umount().isEmpty() )
  569. {
  570. Smb4KSettings::self()->smb4k_umountItem()->setDefault();
  571. }
  572. }
  573. if ( !program_list["smb4k_kill"] )
  574. {
  575. missing.append( "smb4k_kill" );
  576. }
  577. else
  578. {
  579. Smb4KSettings::self()->smb4k_killItem()->setDefaultValue( program_paths["smb4k_kill"] );
  580. if ( Smb4KSettings::smb4k_kill().isEmpty() )
  581. {
  582. Smb4KSettings::self()->smb4k_killItem()->setDefault();
  583. }
  584. }
  585. if ( !program_list["smb4k_cat"] )
  586. {
  587. missing.append( "smb4k_cat" );
  588. }
  589. else
  590. {
  591. Smb4KSettings::self()->smb4k_catItem()->setDefaultValue( program_paths["smb4k_cat"] );
  592. if ( Smb4KSettings::smb4k_cat().isEmpty() )
  593. {
  594. Smb4KSettings::self()->smb4k_catItem()->setDefault();
  595. }
  596. }
  597. if ( !program_list["smb4k_mv"] )
  598. {
  599. missing.append( "smb4k_mv" );
  600. }
  601. else
  602. {
  603. Smb4KSettings::self()->smb4k_mvItem()->setDefaultValue( program_paths["smb4k_mv"] );
  604. if ( Smb4KSettings::smb4k_mv().isEmpty() )
  605. {
  606. Smb4KSettings::self()->smb4k_mvItem()->setDefault();
  607. }
  608. }
  609. if ( !missing.isEmpty() )
  610. {
  611. // Error out if one of the mandatory programs is
  612. // missing:
  613. Smb4KError::error( ERROR_MISSING_PROGRAMS, missing.join( ", " ) );
  614. exit( EXIT_FAILURE );
  615. }
  616. else
  617. {
  618. // Check for the optional programs:
  619. if ( !program_list["super"] )
  620. {
  621. if ( (Smb4KSettings::useForceUnmount() ||
  622. Smb4KSettings::alwaysUseSuperUser()) &&
  623. Smb4KSettings::superUserProgram() ==
  624. Smb4KSettings::EnumSuperUserProgram::Super )
  625. {
  626. Smb4KError::information( INFO_DISABLE_SUID_FEATURE, "super" );
  627. // Reset the super user settings:
  628. Smb4KSettings::self()->useForceUnmountItem()->setDefault();
  629. Smb4KSettings::self()->alwaysUseSuperUserItem()->setDefault();
  630. }
  631. else
  632. {
  633. // Do nothing
  634. }
  635. }
  636. else
  637. {
  638. Smb4KSettings::self()->superItem()->setDefaultValue( program_paths["super"] );
  639. if ( Smb4KSettings::super().isEmpty() )
  640. {
  641. Smb4KSettings::self()->superItem()->setDefault();
  642. }
  643. }
  644. if ( !program_list["sudo"] )
  645. {
  646. if ( (Smb4KSettings::useForceUnmount() ||
  647. Smb4KSettings::alwaysUseSuperUser()) &&
  648. Smb4KSettings::superUserProgram() ==
  649. Smb4KSettings::EnumSuperUserProgram::Super )
  650. {
  651. Smb4KError::information( INFO_DISABLE_SUID_FEATURE, "sudo" );
  652. // Reset the super user settings:
  653. Smb4KSettings::self()->useForceUnmountItem()->setDefault();
  654. Smb4KSettings::self()->alwaysUseSuperUserItem()->setDefault();
  655. }
  656. else
  657. {
  658. // Do nothing
  659. }
  660. }
  661. else
  662. {
  663. Smb4KSettings::self()->sudoItem()->setDefaultValue( program_paths["sudo"] );
  664. if ( Smb4KSettings::sudo().isEmpty() )
  665. {
  666. Smb4KSettings::self()->sudoItem()->setDefault();
  667. }
  668. }
  669. if ( program_list["dvips"] )
  670. {
  671. Smb4KSettings::self()->dvipsItem()->setDefaultValue( program_paths["dvips"] );
  672. if ( Smb4KSettings::dvips().isEmpty() )
  673. {
  674. Smb4KSettings::self()->dvipsItem()->setDefault();
  675. }
  676. }
  677. if ( program_list["enscript"] )
  678. {
  679. Smb4KSettings::self()->enscriptItem()->setDefaultValue( program_paths["enscript"] );
  680. if ( Smb4KSettings::enscript().isEmpty() )
  681. {
  682. Smb4KSettings::self()->enscriptItem()->setDefault();
  683. }
  684. }
  685. if ( program_list["rsync"] )
  686. {
  687. Smb4KSettings::self()->rsyncItem()->setDefaultValue( program_paths["rsync"] );
  688. if ( Smb4KSettings::rsync().isEmpty() )
  689. {
  690. Smb4KSettings::self()->rsyncItem()->setDefault();
  691. }
  692. }
  693. if ( program_list["konsole"] )
  694. {
  695. Smb4KSettings::self()->konsoleItem()->setDefaultValue( program_paths["konsole"] );
  696. if ( Smb4KSettings::konsole().isEmpty() )
  697. {
  698. Smb4KSettings::self()->konsoleItem()->setDefault();
  699. }
  700. }
  701. // Write the configuration to disk:
  702. Smb4KSettings::writeConfig();
  703. }
  704. }
  705. void Smb4KCore::setDefaultSettings()
  706. {
  707. // Samba options that have to be dynamically imported from smb.conf:
  708. TQMap<TQString, TQString> opts = optionsHandler()->globalSambaOptions();
  709. if ( !opts["netbios name"].isEmpty() )
  710. {
  711. Smb4KSettings::self()->netBIOSNameItem()->setDefaultValue( opts["netbios name"] );
  712. if ( Smb4KSettings::netBIOSName().isEmpty() )
  713. {
  714. Smb4KSettings::self()->netBIOSNameItem()->setDefault();
  715. }
  716. }
  717. if ( !opts["workgroup"].isEmpty() )
  718. {
  719. Smb4KSettings::self()->domainNameItem()->setDefaultValue( opts["workgroup"] );
  720. if ( Smb4KSettings::domainName().isEmpty() )
  721. {
  722. Smb4KSettings::self()->domainNameItem()->setDefault();
  723. }
  724. }
  725. if ( !opts["socket options"].isEmpty() )
  726. {
  727. Smb4KSettings::self()->socketOptionsItem()->setDefaultValue( opts["socket options"] );
  728. if ( Smb4KSettings::socketOptions().isEmpty() )
  729. {
  730. Smb4KSettings::self()->socketOptionsItem()->setDefault();
  731. }
  732. }
  733. if ( !opts["netbios scope"].isEmpty() )
  734. {
  735. Smb4KSettings::self()->netBIOSScopeItem()->setDefaultValue( opts["netbios scope"] );
  736. if ( Smb4KSettings::netBIOSScope().isEmpty() )
  737. {
  738. Smb4KSettings::self()->netBIOSScopeItem()->setDefault();
  739. }
  740. }
  741. if ( !opts["name resolve order"].isEmpty() )
  742. {
  743. Smb4KSettings::self()->nameResolveOrderItem()->setDefaultValue( opts["name resolve order"] );
  744. if ( Smb4KSettings::nameResolveOrder().isEmpty() )
  745. {
  746. Smb4KSettings::self()->nameResolveOrderItem()->setDefault();
  747. }
  748. }
  749. if ( !opts["interfaces"].isEmpty() )
  750. {
  751. Smb4KSettings::self()->broadcastAddressItem()->setDefaultValue( opts["interfaces"] );
  752. if ( Smb4KSettings::broadcastAddress().isEmpty() )
  753. {
  754. Smb4KSettings::self()->broadcastAddressItem()->setDefault();
  755. }
  756. }
  757. }
  758. /////////////////////////////////////////////////////////////////////////////
  759. // TQT_SLOT IMPLEMENTATIONS
  760. /////////////////////////////////////////////////////////////////////////////
  761. void Smb4KCore::slotSetScannerState( int state )
  762. {
  763. m_scanner_state = state;
  764. setCurrentState( state );
  765. emit runStateChanged();
  766. }
  767. void Smb4KCore::slotSetMounterState( int state )
  768. {
  769. m_mounter_state = state;
  770. setCurrentState( state );
  771. emit runStateChanged();
  772. }
  773. void Smb4KCore::slotSetPrinterHandlerState( int state )
  774. {
  775. m_print_state = state;
  776. setCurrentState( state );
  777. emit runStateChanged();
  778. }
  779. void Smb4KCore::slotSetSynchronizerState( int state )
  780. {
  781. m_syncer_state = state;
  782. setCurrentState( state );
  783. emit runStateChanged();
  784. }
  785. void Smb4KCore::slotSetPreviewerState( int state )
  786. {
  787. m_previewer_state = state;
  788. setCurrentState( state );
  789. emit runStateChanged();
  790. }
  791. void Smb4KCore::slotShutdown()
  792. {
  793. Smb4KSettings::writeConfig();
  794. }
  795. #include "smb4kcore.moc"