]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QURL.C
The big renaming. Yowser.
[lyx.git] / src / frontends / qt2 / QURL.C
1 /**
2  * \file QURL.C
3  * Copyright 2001 the LyX Team
4  * Read the file COPYING
5  *
6  * \author John Levon
7  */
8
9 #include <config.h>
10
11 #include "QURLDialog.h"
12 #include "QtLyXView.h"
13 #include "BufferView.h" 
14
15 #include "Dialogs.h"
16 #include "QURL.h"
17 #include "gettext.h"
18 #include "buffer.h"
19 #include "lyxfunc.h" 
20
21 #include <qlineedit.h>
22 #include <qcheckbox.h>
23 #include <qpushbutton.h>
24
25 QURL::QURL(LyXView *v, Dialogs *d)
26         : dialog_(0), lv_(v), d_(d), inset_(0), h_(0), u_(0), ih_(0)
27 {
28         // let the dialog be shown
29         // This is a permanent connection so we won't bother
30         // storing a copy because we won't be disconnecting.
31         d->showUrl.connect(slot(this, &QURL::showUrl));
32         d->createUrl.connect(slot(this, &QURL::createUrl));
33 }
34
35  
36 QURL::~QURL()
37 {
38         delete dialog_;
39 }
40
41
42 void QURL::showUrl(InsetCommand * const inset)
43 {
44         // FIXME: when could inset be 0 here ?
45         if (inset==0)
46                 return;
47
48         inset_ = inset;
49         readonly = lv_->buffer()->isReadonly();
50         //ih_ = inset_->hide.connect(slot(this,&QURL::hide));
51         params = inset->params();
52         
53         show();
54 }
55
56  
57 void QURL::createUrl(string const & arg)
58 {
59         // we could already be showing a URL, clear it out
60         if (inset_)
61                 close();
62  
63         readonly = lv_->buffer()->isReadonly();
64         params.setFromString(arg);
65         show();
66 }
67
68  
69 void QURL::update()
70 {
71         dialog_->urlED->setText(params.getContents().c_str());
72         dialog_->nameED->setText(params.getOptions().c_str());
73
74         if (params.getCmdName()=="url") 
75                 dialog_->hyperlinkCB->setChecked(false);
76         else
77                 dialog_->hyperlinkCB->setChecked(true);
78
79         if (readonly) {
80                 dialog_->nameED->setFocusPolicy(QWidget::NoFocus);
81                 dialog_->urlED->setFocusPolicy(QWidget::NoFocus);
82                 dialog_->okPB->setEnabled(false);
83                 dialog_->cancelPB->setText(_("Close"));
84                 dialog_->hyperlinkCB->setEnabled(false);
85         } else {
86                 dialog_->nameED->setFocusPolicy(QWidget::StrongFocus);
87                 dialog_->urlED->setFocusPolicy(QWidget::StrongFocus);
88                 dialog_->urlED->setFocus();
89                 dialog_->okPB->setEnabled(true);
90                 dialog_->cancelPB->setText(_("Cancel"));
91                 dialog_->hyperlinkCB->setEnabled(true);
92         }
93 }
94
95  
96 void QURL::apply()
97 {
98         if (readonly)
99                 return;
100
101         params.setContents(dialog_->urlED->text().latin1());
102         params.setOptions(dialog_->nameED->text().latin1());
103
104         if (dialog_->hyperlinkCB->isChecked())
105                 params.setCmdName("htmlurl");
106         else
107                 params.setCmdName("url");
108
109         if (inset_ != 0) {
110                 if (params != inset_->params()) {
111                         inset_->setParams(params);
112                         lv_->view()->updateInset(inset_, true);
113                 }
114         } else
115                 lv_->getLyXFunc()->dispatch(LFUN_INSERT_URL, params.getAsString().c_str());
116 }
117  
118
119 void QURL::show()
120 {
121         if (!dialog_)
122                 dialog_ = new QURLDialog(this, 0, _("LyX: Url"), false);
123  
124         if (!dialog_->isVisible()) {
125                 h_ = d_->hideBufferDependent.connect(slot(this, &QURL::hide));
126                 //u_ = d_->updateBufferDependent.connect(slot(this, &QURL::update));
127         }
128
129         dialog_->raise();
130         dialog_->setActiveWindow();
131  
132         update();
133         dialog_->show();
134 }
135
136  
137 void QURL::close()
138 {
139         h_.disconnect();
140         u_.disconnect();
141         ih_.disconnect();
142         inset_ = 0;
143 }
144
145  
146 void QURL::hide()
147 {
148         dialog_->hide();
149         close();
150 }