Bibletime – a bible study tool
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.

cswordsetupinstallsourcesdialog.cpp 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*********
  2. *
  3. * This file is part of BibleTime's source code, http://www.bibletime.info/.
  4. *
  5. * Copyright 1999-2006 by the BibleTime developers.
  6. * The BibleTime source code is licensed under the GNU General Public License version 2.0.
  7. *
  8. **********/
  9. //BT includes
  10. #include "cswordsetupinstallsourcesdialog.h"
  11. #include "util/scoped_resource.h"
  12. //TQt includes
  13. #include <tqlayout.h>
  14. #include <tqlabel.h>
  15. #include <tqcombobox.h>
  16. #include <tqlineedit.h>
  17. #include <tqpushbutton.h>
  18. #include <tqmessagebox.h>
  19. #include <tqfileinfo.h>
  20. #include <tdelocale.h>
  21. #include <kdirselectdialog.h>
  22. namespace BookshelfManager {
  23. const TQString PROTO_FILE( i18n("Local") ); //Local path
  24. const TQString PROTO_FTP( i18n("Remote") ); //Remote path
  25. CSwordSetupInstallSourcesDialog::CSwordSetupInstallSourcesDialog(/*TQWidget *parent*/)
  26. : TQDialog() {
  27. TQVBoxLayout* mainLayout = new TQVBoxLayout( this );
  28. mainLayout->setMargin( 10 );
  29. mainLayout->setSpacing( 5 );
  30. TQHBoxLayout *captionLayout = new TQHBoxLayout( mainLayout );
  31. TQLabel *label = new TQLabel( i18n("Caption"), this );
  32. captionLayout->addWidget( label );
  33. m_captionEdit = new TQLineEdit( this );
  34. m_captionEdit->setText("Crosswire Bible Society");
  35. captionLayout->addWidget( m_captionEdit );
  36. mainLayout->addSpacing( 10 );
  37. TQGridLayout* layout = new TQGridLayout( mainLayout, 3, 3 );
  38. layout->setSpacing( 5 );
  39. label = new TQLabel(i18n("Type"), this);
  40. layout->addWidget( label, 0, 0);
  41. m_serverLabel = new TQLabel(i18n("Server"), this);
  42. layout->addWidget( m_serverLabel, 0, 1);
  43. label = new TQLabel(i18n("Path"), this);
  44. layout->addWidget( label, 0, 2 );
  45. m_protocolCombo = new TQComboBox( this );
  46. layout->addWidget(m_protocolCombo, 1, 0);
  47. m_protocolCombo->insertItem( PROTO_FTP );
  48. m_protocolCombo->insertItem( PROTO_FILE );
  49. m_serverEdit = new TQLineEdit( this );
  50. layout->addWidget( m_serverEdit, 1, 1 );
  51. m_serverEdit->setText("ftp.crosswire.org");
  52. m_pathEdit = new TQLineEdit( this );
  53. layout->addWidget( m_pathEdit, 1, 2 );
  54. m_pathEdit->setText("/pub/sword/raw");
  55. mainLayout->addSpacing( 10 );
  56. TQHBoxLayout* buttonLayout = new TQHBoxLayout( mainLayout );
  57. buttonLayout->addStretch();
  58. TQPushButton* okButton = new TQPushButton( i18n("Ok"), this);
  59. TQPushButton* discardButton = new TQPushButton( i18n("Discard"), this);
  60. buttonLayout->addWidget( discardButton);
  61. buttonLayout->addWidget( okButton);
  62. buttonLayout->addStretch();
  63. connect( okButton, TQT_SIGNAL( clicked() ), this, TQT_SLOT( slotOk() ) );
  64. connect( discardButton, TQT_SIGNAL( clicked() ), this, TQT_SLOT( reject() ) );
  65. connect( m_protocolCombo, TQT_SIGNAL( activated(int) ), this, TQT_SLOT( slotProtocolChanged() ) );
  66. }
  67. void CSwordSetupInstallSourcesDialog::slotOk() {
  68. //run a few tests to validate the input first
  69. if ( m_captionEdit->text().stripWhiteSpace().isEmpty() ) { //no caption
  70. TQMessageBox::information( this, i18n( "Error" ), i18n("Please provide a caption."), TQMessageBox::Retry);
  71. return;
  72. }
  73. BTInstallMgr iMgr;
  74. sword::InstallSource is = BTInstallMgr::Tool::RemoteConfig::source( &iMgr, m_captionEdit->text() );
  75. if ( (TQString)is.caption.c_str() == m_captionEdit->text() ) { //source already exists
  76. TQMessageBox::information( this, i18n( "Error" ),
  77. i18n("A source with this caption already exists.<br>Please provide a different caption."), TQMessageBox::Retry);
  78. return;
  79. }
  80. if ( m_protocolCombo->currentText() == PROTO_FTP &&
  81. m_serverEdit->text().stripWhiteSpace().isEmpty() ) { //no server name
  82. TQMessageBox::information( this, i18n( "Error" ), i18n("Please provide a server name."), TQMessageBox::Retry);
  83. return;
  84. }
  85. if ( m_protocolCombo->currentText() == PROTO_FILE) {
  86. const TQFileInfo fi( m_pathEdit->text() );
  87. if (!fi.exists() || !fi.isReadable()) { //no valid and readable path
  88. TQMessageBox::information( this, i18n( "Error" ), i18n("Please provide a valid, readable path."), TQMessageBox::Retry);
  89. return;
  90. }
  91. else if ( m_pathEdit->text().isEmpty() ) {
  92. TQMessageBox::information( this, i18n( "Error" ), i18n("Please provide a path."), TQMessageBox::Retry);
  93. }
  94. }
  95. accept(); //only if nothing else failed
  96. }
  97. void CSwordSetupInstallSourcesDialog::slotProtocolChanged() {
  98. if (m_protocolCombo->currentText() == PROTO_FTP) { //REMOTE
  99. m_serverLabel->show();
  100. m_serverEdit->show();
  101. }
  102. else { //LOCAL, no server needed
  103. m_serverLabel->hide();
  104. m_serverEdit->hide();
  105. KURL url = KDirSelectDialog::selectDirectory(TQString(), true);
  106. if (url.isValid()) {
  107. m_pathEdit->setText( url.path() );
  108. }
  109. }
  110. }
  111. sword::InstallSource CSwordSetupInstallSourcesDialog::getSource() {
  112. util::scoped_ptr<CSwordSetupInstallSourcesDialog> dlg( new CSwordSetupInstallSourcesDialog() );
  113. sword::InstallSource newSource(""); //empty, invalid Source
  114. if (dlg->exec() == TQDialog::Accepted) {
  115. if (dlg->m_protocolCombo->currentText() == PROTO_FTP) {
  116. newSource.type = "FTP";
  117. newSource.source = dlg->m_serverEdit->text().utf8();
  118. //a message to the user would be nice, but we're in message freeze right now (1.5.1)
  119. if (dlg->m_serverEdit->text().right(1) == "/") { //remove a trailing slash
  120. newSource.source = dlg->m_serverEdit->text().mid(0, dlg->m_serverEdit->text().length()-1).utf8();
  121. }
  122. }
  123. else {
  124. newSource.type = "DIR";
  125. newSource.source = "local";
  126. }
  127. newSource.caption = dlg->m_captionEdit->text().utf8();
  128. newSource.directory = dlg->m_pathEdit->text().utf8();
  129. }
  130. return newSource;
  131. }
  132. } //namespace
  133. #include "cswordsetupinstallsourcesdialog.moc"