1 /* This file is part of the KDE project
2 Copyright (C) 2003 Alexander Kellett <lypanov@kde.org>
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public
6 License version 2 as published by the Free Software Foundation.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 General Public License for more details.
13 You should have received a copy of the GNU General Public License
14 along with this program; see the file COPYING. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
19 #include "bookmarkinfo.h"
20 #include "bookmarklistview.h"
23 #include "bookmarkmodel.h"
27 #include <QtCore/QTimer>
28 #include <QtGui/QLabel>
29 #include <QtGui/QGridLayout>
34 #include <kapplication.h>
35 #include <kstandardaction.h>
38 #include <kedittoolbar.h>
39 #include <kmessagebox.h>
40 #include <klineedit.h>
41 #include <kfiledialog.h>
43 #include <kbookmark.h>
44 #include <kbookmarkmanager.h>
45 #include <QtCore/QEvent>
47 // SHUFFLE all these functions around, the order is just plain stupid
48 void BookmarkInfoWidget::showBookmark(const KBookmark
&bk
) {
53 // all read only and blank
55 m_title_le
->setReadOnly(true);
56 m_title_le
->setText(QString());
58 m_url_le
->setReadOnly(true);
59 m_url_le
->setText(QString());
61 m_comment_le
->setReadOnly(true);
62 m_comment_le
->setText(QString());
64 m_visitdate_le
->setReadOnly(true);
65 m_visitdate_le
->setText(QString());
67 m_credate_le
->setReadOnly(true);
68 m_credate_le
->setText(QString());
70 m_visitcount_le
->setReadOnly(true);
71 m_visitcount_le
->setText(QString());
77 m_title_le
->setReadOnly( (bk
.isSeparator()|| !bk
.hasParent() )? true : false);
78 if (bk
.fullText() != m_title_le
->text())
79 m_title_le
->setText(bk
.fullText());
81 m_url_le
->setReadOnly(bk
.isGroup() || bk
.isSeparator());
83 m_url_le
->setText(QString());
86 // Update the text if and only if the text represents a different URL to that
87 // of the current bookmark - the old method, "m_url_le->text() != bk.url().pathOrUrl()",
88 // created difficulties due to the ambiguity of converting URLs to text. (#172647)
89 if (KUrl(m_url_le
->text()) != bk
.url()) {
90 const int cursorPosition
= m_url_le
->cursorPosition();
91 m_url_le
->setText(bk
.url().pathOrUrl());
92 m_url_le
->setCursorPosition(cursorPosition
);
96 m_comment_le
->setReadOnly((bk
.isSeparator()|| !bk
.hasParent()) ? true : false );
97 QString commentText
= EditCommand::getNodeText(bk
, QStringList() << "desc");
98 if (m_comment_le
->text() != commentText
) {
99 const int cursorPosition
= m_comment_le
->cursorPosition();
100 m_comment_le
->setText(commentText
);
101 m_comment_le
->setCursorPosition(cursorPosition
);
109 void BookmarkInfoWidget::updateStatus()
111 //FIXME we don't want every metadata element, but only that with owner "http://www.kde.org"
113 CurrentMgr::makeTimeStr( EditCommand::getNodeText(m_bk
, QStringList() << "info" << "metadata"
114 << "time_visited" ));
115 m_visitdate_le
->setReadOnly(true);
116 m_visitdate_le
->setText(visitDate
);
118 QString creationDate
=
119 CurrentMgr::makeTimeStr( EditCommand::getNodeText(m_bk
, QStringList() << "info" << "metadata"
121 m_credate_le
->setReadOnly(true);
122 m_credate_le
->setText(creationDate
);
124 // TODO - get the actual field name from the spec if it exists, else copy galeon
125 m_visitcount_le
->setReadOnly(true);
126 m_visitcount_le
->setText(
127 EditCommand::getNodeText(m_bk
, QStringList() << "info" << "metadata"
131 void BookmarkInfoWidget::commitChanges()
138 void BookmarkInfoWidget::commitTitle()
142 CurrentMgr::self()->notifyManagers(CurrentMgr::bookmarkAt(titlecmd
->affectedBookmarks()).toGroup());
147 void BookmarkInfoWidget::slotTextChangedTitle(const QString
&str
)
149 if (m_bk
.isNull() || !m_title_le
->isModified())
156 titlecmd
->modify(str
);
161 titlecmd
= new EditCommand(m_bk
.address(), 0, str
);
163 CmdHistory::self()->addInFlightCommand(titlecmd
);
167 void BookmarkInfoWidget::commitURL()
171 CurrentMgr::self()->notifyManagers(CurrentMgr::bookmarkAt(urlcmd
->affectedBookmarks()).toGroup());
176 void BookmarkInfoWidget::slotTextChangedURL(const QString
&str
) {
177 if (m_bk
.isNull() || !m_url_le
->isModified())
189 urlcmd
= new EditCommand(m_bk
.address(), 1, str
);
191 CmdHistory::self()->addInFlightCommand(urlcmd
);
195 void BookmarkInfoWidget::commitComment()
199 CurrentMgr::self()->notifyManagers( CurrentMgr::bookmarkAt( commentcmd
->affectedBookmarks() ).toGroup());
204 void BookmarkInfoWidget::slotTextChangedComment(const QString
&str
) {
205 if (m_bk
.isNull() || !m_comment_le
->isModified())
212 commentcmd
->modify(str
);
213 commentcmd
->execute();
217 commentcmd
= new EditCommand(m_bk
.address(), 2, str
);
218 commentcmd
->execute();
219 CmdHistory::self()->addInFlightCommand(commentcmd
);
223 void BookmarkInfoWidget::slotUpdate()
225 const QModelIndexList
& list
= mBookmarkListView
->selectionModel()->selectedRows();
226 if( list
.count() == 1)
228 QModelIndex index
= *list
.constBegin();
229 showBookmark( mBookmarkListView
->bookmarkModel()->bookmarkForIndex(index
) );
232 showBookmark( KBookmark() );
235 BookmarkInfoWidget::BookmarkInfoWidget(BookmarkListView
* lv
, QWidget
*parent
)
236 : QWidget(parent
), mBookmarkListView(lv
) {
238 connect(mBookmarkListView
->selectionModel(), SIGNAL(selectionChanged(const QItemSelection
&, const QItemSelection
&)),
239 SLOT( slotUpdate()));
241 connect(mBookmarkListView
->model(), SIGNAL(dataChanged( const QModelIndex
&, const QModelIndex
&)),
242 SLOT( slotUpdate()));
244 timer
= new QTimer(this);
245 timer
->setSingleShot(true);
246 connect(timer
, SIGNAL( timeout() ), SLOT( commitChanges()));
253 QGridLayout
*grid
= new QGridLayout(this);
256 m_title_le
= new KLineEdit(this);
257 m_title_le
->setClearButtonShown(true);
258 grid
->addWidget(m_title_le
, 0, 1);
259 QLabel
* label
= new QLabel(i18n("Name:"), this);
260 label
->setBuddy(m_title_le
);
261 grid
->addWidget(label
, 0, 0);
263 connect(m_title_le
, SIGNAL( textChanged(const QString
&) ),
264 SLOT( slotTextChangedTitle(const QString
&) ));
265 connect(m_title_le
, SIGNAL( editingFinished() ), SLOT( commitTitle() ));
267 m_url_le
= new KLineEdit(this);
268 m_url_le
->setClearButtonShown(true);
269 grid
->addWidget(m_url_le
, 1, 1);
270 label
= new QLabel(i18n("Location:"), this);
271 label
->setBuddy(m_url_le
);
272 grid
->addWidget(label
, 1, 0);
274 connect(m_url_le
, SIGNAL( textChanged(const QString
&) ),
275 SLOT( slotTextChangedURL(const QString
&) ));
276 connect(m_url_le
, SIGNAL( editingFinished() ), SLOT( commitURL() ));
278 m_comment_le
= new KLineEdit(this);
279 m_comment_le
->setClearButtonShown(true);
280 grid
->addWidget(m_comment_le
, 2, 1);
281 label
= new QLabel(i18n("Comment:"), this);
282 label
->setBuddy(m_comment_le
);
283 grid
->addWidget(label
, 2, 0);
285 connect(m_comment_le
, SIGNAL( textChanged(const QString
&) ),
286 SLOT( slotTextChangedComment(const QString
&) ));
287 connect(m_comment_le
, SIGNAL( editingFinished() ), SLOT( commitComment() ));
289 m_credate_le
= new KLineEdit(this);
290 grid
->addWidget(m_credate_le
, 0, 3);
291 label
= new QLabel(i18n("First viewed:"), this);
292 label
->setBuddy(m_credate_le
);
293 grid
->addWidget(label
, 0, 2);
295 m_visitdate_le
= new KLineEdit(this);
296 grid
->addWidget(m_visitdate_le
, 1, 3);
297 label
= new QLabel(i18n("Viewed last:"), this);
298 label
->setBuddy(m_visitdate_le
);
299 grid
->addWidget(label
, 1, 2 );
301 m_visitcount_le
= new KLineEdit(this);
302 grid
->addWidget(m_visitcount_le
, 2, 3);
303 label
= new QLabel(i18n("Times visited:"), this);
304 label
->setBuddy(m_visitcount_le
);
305 grid
->addWidget(label
, 2, 2);
307 showBookmark(KBookmark());
310 #include "bookmarkinfo.moc"