]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt2/QURL.C
Some string(widget->text()) fixes. Weirdness
[lyx.git] / src / frontends / qt2 / QURL.C
index 470a12220c8addb1dead6fcee9016c3d9f37fdf7..67b8023b90194b330eeddde81d867c51b1ee8e4f 100644 (file)
 /**
  * \file QURL.C
- * Copyright 2001 the LyX Team
- * Read the file COPYING
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
  *
  * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS
  */
 
 #include <config.h>
 
-#include "QURLDialog.h"
-#include "QtLyXView.h"
-#include "BufferView.h" 
+#ifdef __GNUG__
+#pragma implementation
+#endif
 
-#include "Dialogs.h"
-#include "QURL.h"
+#include "ControlUrl.h"
+#include "debug.h"
 #include "gettext.h"
-#include "buffer.h"
-#include "lyxfunc.h" 
 
-#include <qlineedit.h>
+#include "QURL.h"
+#include "QURLDialog.h"
+#include "Qt2BC.h"
+
 #include <qcheckbox.h>
 #include <qpushbutton.h>
+#include <qlineedit.h>
+
+typedef Qt2CB<ControlUrl, Qt2DB<QURLDialog> > base_class;
 
-QURL::QURL(LyXView *v, Dialogs *d)
-       : dialog_(0), lv_(v), d_(d), inset_(0), h_(0), u_(0), ih_(0)
-{
-       // let the dialog be shown
-       // This is a permanent connection so we won't bother
-       // storing a copy because we won't be disconnecting.
-       d->showUrl.connect(slot(this, &QURL::showUrl));
-       d->createUrl.connect(slot(this, &QURL::createUrl));
-}
 
-QURL::~QURL()
+QURL::QURL()
+       : base_class(_("URL"))
 {
-       delete dialog_;
 }
 
 
-void QURL::showUrl(InsetCommand * const inset)
+void QURL::build_dialog()
 {
-       // FIXME: when could inset be 0 here ?
-       if (inset==0)
-               return;
-
-       inset_ = inset;
-       readonly = lv_->buffer()->isReadonly();
-       //ih_ = inset_->hide.connect(slot(this,&QURL::hide));
-       params = inset->params();
-       
-       show();
-}
+       dialog_.reset(new QURLDialog(this));
 
-void QURL::createUrl(string const & arg)
-{
-       // we could already be showing a URL, clear it out
-       if (inset_)
-               close();
-       readonly = lv_->buffer()->isReadonly();
-       params.setFromString(arg);
-       show();
+       bc().setOK(dialog_->okPB);
+       bc().setCancel(dialog_->closePB);
+       bc().addReadOnly(dialog_->urlED);
+       bc().addReadOnly(dialog_->nameED);
+       bc().addReadOnly(dialog_->hyperlinkCB);
 }
 
-void QURL::update()
+
+void QURL::update_contents()
 {
+       InsetCommandParams const & params = controller().params();
+
        dialog_->urlED->setText(params.getContents().c_str());
        dialog_->nameED->setText(params.getOptions().c_str());
-
-       if (params.getCmdName()=="url") 
-               dialog_->hyperlinkCB->setChecked(false);
-       else
-               dialog_->hyperlinkCB->setChecked(true);
-
-       if (readonly) {
-               dialog_->nameED->setFocusPolicy(QWidget::NoFocus);
-               dialog_->urlED->setFocusPolicy(QWidget::NoFocus);
-               dialog_->okPB->setEnabled(false);
-               dialog_->cancelPB->setText(_("Close"));
-               dialog_->hyperlinkCB->setEnabled(false);
-       } else {
-               dialog_->nameED->setFocusPolicy(QWidget::StrongFocus);
-               dialog_->urlED->setFocusPolicy(QWidget::StrongFocus);
-               dialog_->urlED->setFocus();
-               dialog_->okPB->setEnabled(true);
-               dialog_->cancelPB->setText(_("Cancel"));
-               dialog_->hyperlinkCB->setEnabled(true);
-       }
+       dialog_->hyperlinkCB->setChecked(params.getCmdName() != "url");
 }
 
+
 void QURL::apply()
 {
-       if (readonly)
-               return;
+       InsetCommandParams & params = controller().params();
 
        params.setContents(dialog_->urlED->text().latin1());
        params.setOptions(dialog_->nameED->text().latin1());
@@ -105,46 +68,13 @@ void QURL::apply()
                params.setCmdName("htmlurl");
        else
                params.setCmdName("url");
-
-       if (inset_ != 0) {
-               if (params != inset_->params()) {
-                       inset_->setParams(params);
-                       lv_->view()->updateInset(inset_, true);
-               }
-       } else
-               lv_->getLyXFunc()->dispatch(LFUN_INSERT_URL, params.getAsString().c_str());
 }
 
-void QURL::show()
-{
-       if (!dialog_)
-               dialog_ = new QURLDialog(this, 0, _("LyX: Url"), false);
-       if (!dialog_->isVisible()) {
-               h_ = d_->hideBufferDependent.connect(slot(this, &QURL::hide));
-               //u_ = d_->updateBufferDependent.connect(slot(this, &QURL::update));
-       }
-
-       dialog_->raise();
-       dialog_->setActiveWindow();
-       update();
-       dialog_->show();
-}
 
-void QURL::close()
+bool QURL::isValid()
 {
-       h_.disconnect();
-       u_.disconnect();
-       ih_.disconnect();
-       inset_ = 0;
-}
+       string const u(dialog_->urlED->text().latin1());
+       string const n(dialog_->nameED->text().latin1());
 
-void QURL::hide()
-{
-       dialog_->hide();
-       close();
+       return !u.empty() && !n.empty();
 }