00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "adddocitemdlg.h"
00015 #include "misc.h"
00016
00017 #include <qlabel.h>
00018 #include <qlayout.h>
00019 #include <qpushbutton.h>
00020 #include <qwhatsthis.h>
00021 #include <qdom.h>
00022 #include <kbuttonbox.h>
00023 #include <kfiledialog.h>
00024 #include <klocale.h>
00025 #include <kstdguiitem.h>
00026 #include <klineedit.h>
00027 #include <kdeversion.h>
00028
00029 AddDocItemDialog::AddDocItemDialog(KFile::Mode mode, QString filter, TitleType checkDocTitle, QString title, QString url, QWidget *parent, const char *name)
00030 : QDialog(parent, name, true), m_mode(mode), m_type(checkDocTitle), m_filter(filter)
00031 {
00032 setCaption(i18n("Add Documentation Entry"));
00033
00034 title_check = 0;
00035 if (m_type == Qt)
00036 title_check = new QCheckBox(i18n("Custom title"), this);
00037
00038 QLabel *title_label = new QLabel(i18n("&Title:"), this);
00039 title_edit = new QLineEdit(this);
00040 title_edit->setText(title);
00041 title_edit->setFocus();
00042 title_label->setBuddy(title_edit);
00043
00044 QLabel *url_label = new QLabel(i18n("&Location:"), this);
00045 url_edit = new KURLRequester(this);
00046 url_label->setBuddy(url_edit);
00047 QFontMetrics fm(url_edit->fontMetrics());
00048 url_edit->setURL(url);
00049 url_edit->setMinimumWidth(fm.width('X')*35);
00050 url_edit->setFilter(m_filter);
00051 url_edit->setMode((int) m_mode);
00052
00053
00054
00055
00056
00057
00058 QString s = i18n("Enter the name of the entry here.");
00059 QWhatsThis::add(title_label, s);
00060 QWhatsThis::add(title_edit, s);
00061 s = i18n("Enter the location of the entry here.");
00062 QWhatsThis::add(url_label, s);
00063 QWhatsThis::add(url_edit, s);
00064
00065
00066
00067 QVBoxLayout *layout = new QVBoxLayout(this, 10);
00068
00069 QGridLayout *grid = new QGridLayout(2, 3);
00070 if (m_type == Qt)
00071 {
00072 layout->addWidget(title_check);
00073 }
00074 layout->addLayout(grid);
00075 grid->addWidget(title_label, 0, 0);
00076 grid->addMultiCellWidget(title_edit, 0, 0, 1, 2);
00077 grid->addWidget(url_label, 1, 0);
00078 grid->addWidget(url_edit, 1, 1);
00079
00080
00081 QFrame *frame = new QFrame(this);
00082 frame->setFrameStyle(QFrame::HLine | QFrame::Sunken);
00083 layout->addWidget(frame, 0);
00084
00085 KButtonBox *buttonbox = new KButtonBox(this);
00086 buttonbox->addStretch();
00087 #if KDE_IS_VERSION( 3, 2, 90 )
00088 m_pOk = buttonbox->addButton(KStdGuiItem::ok());
00089 QPushButton *cancel = buttonbox->addButton(KStdGuiItem::cancel());
00090 #else
00091 m_pOk = buttonbox->addButton(KStdGuiItem::ok().text());
00092 QPushButton *cancel = buttonbox->addButton(KStdGuiItem::cancel().text());
00093 #endif
00094 m_pOk->setDefault(true);
00095 connect( m_pOk, SIGNAL(clicked()), this, SLOT(accept()) );
00096 connect( cancel, SIGNAL(clicked()), this, SLOT(reject()) );
00097 buttonbox->layout();
00098 layout->addWidget(buttonbox, 0);
00099
00100 if (m_type != None)
00101 {
00102 title_edit->setEnabled(false);
00103 if (m_type == Qt)
00104 connect(title_check, SIGNAL(toggled(bool)), title_edit, SLOT(setEnabled(bool)));
00105 connect(url_edit, SIGNAL(textChanged(const QString&)), this, SLOT(setTitle(const QString&)));
00106 }
00107 connect( url_edit, SIGNAL(textChanged(const QString&)), this, SLOT(setLocationChanged(const QString&)));
00108 setLocationChanged(url_edit->lineEdit()->text() );
00109 }
00110
00111
00112 AddDocItemDialog::~AddDocItemDialog()
00113 {}
00114
00115 void AddDocItemDialog::setLocationChanged(const QString & _text )
00116 {
00117 m_pOk->setEnabled( !_text.isEmpty() );
00118 }
00119
00120 void AddDocItemDialog::setTitle(const QString &str)
00121 {
00122 if ( m_type == Qt)
00123 {
00124 if (title_check->isChecked())
00125 return;
00126 title_edit->setText("");
00127 QFileInfo fi(str);
00128 if (!fi.exists())
00129 return;
00130
00131 QFile f(str);
00132 if (!f.open(IO_ReadOnly)) {
00133 return;
00134 }
00135 QDomDocument doc;
00136 if (!doc.setContent(&f) || doc.doctype().name() != "DCF") {
00137 return;
00138 }
00139 f.close();
00140
00141 QDomElement docEl = doc.documentElement();
00142
00143 title_edit->setText(docEl.attribute("title", QString::null));
00144 }
00145 else if (m_type == DevHelp)
00146 {
00147 title_edit->setText("");
00148 QFileInfo fi(str);
00149 if (!fi.exists())
00150 return;
00151
00152 QFile f(str);
00153 if (!f.open(IO_ReadOnly)) {
00154 return;
00155 }
00156 QDomDocument doc;
00157 if (!doc.setContent(&f)) {
00158 return;
00159 }
00160 f.close();
00161
00162 QDomElement docEl = doc.documentElement();
00163
00164 title_edit->setText(docEl.attribute("title", QString::null));
00165 }
00166 else if (m_type == KDevelopTOC)
00167 {
00168 title_edit->setText(DocTreeViewTool::tocTitle(str));
00169 }
00170 }
00171
00172 #include "adddocitemdlg.moc"