summaryrefslogtreecommitdiffstats
path: root/src/knowitlink.cpp
blob: 7aa3a7f2cda1f0e4cffd1d971cafc867cff80baf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/***************************************************************************
                          knowitlink.cpp  -  description
                             -------------------
    begin                : pi� cze 27 2003
    copyright            : (C) 2003 by Micha� Rudolf
    email                : [email protected]
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include "knowitlink.h"
#include "notes.h"

#include <qtoolbutton.h>
#include <qlabel.h>
#include <qlayout.h>
#include <qvbox.h>

#include <kfiledialog.h>
#include <kglobal.h>
#include <kiconloader.h>
#include <klocale.h>
#include <kcombobox.h>
#include <klineedit.h>

KnowitLinkDialog::KnowitLinkDialog()
   : KDialogBase(Plain, i18n("Modify link"), Ok|Cancel, Ok)
{
   QVBoxLayout* layout = new QVBoxLayout(plainPage());

   QHBox* typeBox = new QHBox(plainPage());
   layout->addWidget(typeBox);
   new QLabel(i18n("Referenced item:"), typeBox);
   linkType = new KComboBox(typeBox, "LinkType");
   linkType->insertItem(i18n("File or URL"));
   linkType->insertItem(i18n("KnowIt note"));

   layout->addItem(new QSpacerItem(0, 5));       
   QHBox* editBox = new QHBox(plainPage());
   layout->addWidget(editBox);
   linkValue = new KLineEdit("Link text", editBox);
   linkValue->setMinimumWidth(300);
   browse = new QToolButton(editBox, "Browse");
   browse->setIconSet(QIconSet(KGlobal::iconLoader()->loadIcon("fileopen",
      KIcon::Toolbar, KIcon::SizeSmall)));
   
   layout->addItem(new QSpacerItem(0, 5));
   layout->addWidget(new QLabel(i18n("Link description:"), plainPage()));
   layout->addWidget(linkDescription = new KLineEdit("Link description", plainPage()));

   connect(browse, SIGNAL(clicked()), this, SLOT(slotBrowse()));
   connect(linkType, SIGNAL(activated(int)), this, SLOT(slotTypeChanged(int)));
}

KnowitLinkDialog::~KnowitLinkDialog()
{
}

bool KnowitLinkDialog::modifyLink(TNoteLink& link)
{
   linkDescription->setText(link.description);
   linkType->setCurrentItem(link.isLocalReference());
   if (link.isLocalReference())
      linkValue->setText(link.link.remove(0, 9));
   else
      linkValue->setText(link.link);
   slotTypeChanged(linkType->currentItem());
   if (exec() == QDialog::Accepted) {
      link.description = linkDescription->text();
      if (linkType->currentItem())
         link.link = "knowit://" + linkValue->text();
      else
         link.link = linkValue->text();
      return true;
   }
   else
      return false;
}

void KnowitLinkDialog::slotBrowse()
{
   KURL url=KFileDialog::getOpenURL(QString::null,
      i18n("*|All files"), this, i18n("Choose link..."));
   if (!url.isEmpty()) {
      linkValue->setText(url.url());
      linkType->setCurrentItem(0);
      }
}

void KnowitLinkDialog::slotTypeChanged(int index)
{
   browse->setEnabled(!index);
}