KnowIt – tool for managing notes
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.

102 lines
3.4KB

  1. /***************************************************************************
  2. knowitlink.cpp - description
  3. -------------------
  4. begin : pi± cze 27 2003
  5. copyright : (C) 2003 by Micha³ Rudolf
  6. email : mrudolf@kdewebdev.org
  7. ***************************************************************************/
  8. /***************************************************************************
  9. * *
  10. * This program is free software; you can redistribute it and/or modify *
  11. * it under the terms of the GNU General Public License as published by *
  12. * the Free Software Foundation; either version 2 of the License, or *
  13. * (at your option) any later version. *
  14. * *
  15. ***************************************************************************/
  16. #include "knowitlink.h"
  17. #include "notes.h"
  18. #include <tqtoolbutton.h>
  19. #include <tqlabel.h>
  20. #include <tqlayout.h>
  21. #include <tqvbox.h>
  22. #include <tdefiledialog.h>
  23. #include <tdeglobal.h>
  24. #include <kiconloader.h>
  25. #include <tdelocale.h>
  26. #include <kcombobox.h>
  27. #include <klineedit.h>
  28. KnowitLinkDialog::KnowitLinkDialog()
  29. : KDialogBase(Plain, i18n("Modify link"), Ok|Cancel, Ok)
  30. {
  31. TQVBoxLayout* layout = new TQVBoxLayout(plainPage());
  32. TQHBox* typeBox = new TQHBox(plainPage());
  33. layout->addWidget(typeBox);
  34. new TQLabel(i18n("Referenced item:"), typeBox);
  35. linkType = new KComboBox(typeBox, "LinkType");
  36. linkType->insertItem(i18n("File or URL"));
  37. linkType->insertItem(i18n("KnowIt note"));
  38. layout->addItem(new TQSpacerItem(0, 5));
  39. TQHBox* editBox = new TQHBox(plainPage());
  40. layout->addWidget(editBox);
  41. linkValue = new KLineEdit("Link text", editBox);
  42. linkValue->setMinimumWidth(300);
  43. browse = new TQToolButton(editBox, "Browse");
  44. browse->setIconSet(TQIconSet(TDEGlobal::iconLoader()->loadIcon("fileopen",
  45. TDEIcon::Toolbar, TDEIcon::SizeSmall)));
  46. layout->addItem(new TQSpacerItem(0, 5));
  47. layout->addWidget(new TQLabel(i18n("Link description:"), plainPage()));
  48. layout->addWidget(linkDescription = new KLineEdit("Link description", plainPage()));
  49. connect(browse, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotBrowse()));
  50. connect(linkType, TQT_SIGNAL(activated(int)), this, TQT_SLOT(slotTypeChanged(int)));
  51. }
  52. KnowitLinkDialog::~KnowitLinkDialog()
  53. {
  54. }
  55. bool KnowitLinkDialog::modifyLink(TNoteLink& link)
  56. {
  57. linkDescription->setText(link.description);
  58. linkType->setCurrentItem(link.isLocalReference());
  59. if (link.isLocalReference())
  60. linkValue->setText(link.link.remove(0, 9));
  61. else
  62. linkValue->setText(link.link);
  63. slotTypeChanged(linkType->currentItem());
  64. if (exec() == TQDialog::Accepted) {
  65. link.description = linkDescription->text();
  66. if (linkType->currentItem())
  67. link.link = "knowit://" + linkValue->text();
  68. else
  69. link.link = linkValue->text();
  70. return true;
  71. }
  72. else
  73. return false;
  74. }
  75. void KnowitLinkDialog::slotBrowse()
  76. {
  77. KURL url=KFileDialog::getOpenURL(TQString(),
  78. i18n("*|All files"), this, i18n("Choose link..."));
  79. if (!url.isEmpty()) {
  80. linkValue->setText(url.url());
  81. linkType->setCurrentItem(0);
  82. }
  83. }
  84. void KnowitLinkDialog::slotTypeChanged(int index)
  85. {
  86. browse->setEnabled(!index);
  87. }