From 53c24201ab19c660c31a104c848b8ca94187b7c4 Mon Sep 17 00:00:00 2001
From: Kevin Smith <git@kismith.co.uk>
Date: Fri, 30 Apr 2010 18:26:24 +0000
Subject: Edit bookmarks with very basic validation.

Doesn't save yet.

diff --git a/Swift/QtUI/QtAddBookmarkWindow.cpp b/Swift/QtUI/QtAddBookmarkWindow.cpp
index 863e98c..2403eac 100644
--- a/Swift/QtUI/QtAddBookmarkWindow.cpp
+++ b/Swift/QtUI/QtAddBookmarkWindow.cpp
@@ -13,9 +13,12 @@ QtAddBookmarkWindow::QtAddBookmarkWindow(UIEventStream* eventStream) : eventStre
 
 }
 
-void QtAddBookmarkWindow::commit() {
-	qDebug() << "committing";
-	eventStream_->send(boost::shared_ptr<UIEvent>(new AddMUCBookmarkUIEvent(createBookmarkFromForm())));
+bool QtAddBookmarkWindow::commit() {
+	boost::shared_ptr<MUCBookmark> bookmark(createBookmarkFromForm());
+	if (bookmark) {
+		eventStream_->send(boost::shared_ptr<UIEvent>(new AddMUCBookmarkUIEvent(bookmark)));
+	}
+	return bookmark;
 }
 
 }
diff --git a/Swift/QtUI/QtAddBookmarkWindow.h b/Swift/QtUI/QtAddBookmarkWindow.h
index 8e33180..f026cc3 100644
--- a/Swift/QtUI/QtAddBookmarkWindow.h
+++ b/Swift/QtUI/QtAddBookmarkWindow.h
@@ -16,7 +16,7 @@ namespace Swift {
 		Q_OBJECT
 		public:
 			QtAddBookmarkWindow(UIEventStream* eventStream);
-			void commit();
+			bool commit();
 		private:
 			UIEventStream* eventStream_;
 	};
diff --git a/Swift/QtUI/QtBookmarkDetailWindow.cpp b/Swift/QtUI/QtBookmarkDetailWindow.cpp
index ef524c3..b27ed7c 100644
--- a/Swift/QtUI/QtBookmarkDetailWindow.cpp
+++ b/Swift/QtUI/QtBookmarkDetailWindow.cpp
@@ -6,6 +6,7 @@
 
 #include "QtBookmarkDetailWindow.h"
 #include "QtSwiftUtil.h"
+#include <QMessageBox>
 
 namespace Swift {
 
@@ -17,15 +18,24 @@ QtBookmarkDetailWindow::QtBookmarkDetailWindow(QWidget* parent) : QDialog(parent
 }
 
 void QtBookmarkDetailWindow::accept() {
-	commit();
-	QDialog::accept();
+	if (commit()) {
+		QDialog::accept();
+	}
 }
 
 boost::shared_ptr<MUCBookmark> QtBookmarkDetailWindow::createBookmarkFromForm() {
 	//check room
 	//check bookmarkName
 	JID room(Q2PSTRING(room_->text()));
+	if (!room.isValid() || room.getNode().isEmpty() || !room.getResource().isEmpty()) {
+		QMessageBox::warning(this, "Bookmark not valid", "You must specify a valid room address (e.g. myroom@chats.example.com).");
+		return boost::shared_ptr<MUCBookmark>();
+	}
 	String name(Q2PSTRING(name_->text()));
+	if (name.isEmpty()) {
+		name = room.toString();
+	}
+
 	String nick(Q2PSTRING(nick_->text()));
 	String password(Q2PSTRING(password_->text()));
 	bool autojoin = autojoin_->isChecked();
diff --git a/Swift/QtUI/QtBookmarkDetailWindow.h b/Swift/QtUI/QtBookmarkDetailWindow.h
index 82bfe9b..dadd973 100644
--- a/Swift/QtUI/QtBookmarkDetailWindow.h
+++ b/Swift/QtUI/QtBookmarkDetailWindow.h
@@ -19,7 +19,7 @@ namespace Swift {
 		Q_OBJECT
 		public:
 			QtBookmarkDetailWindow(QWidget* parent = NULL);
-			virtual void commit() = 0;
+			virtual bool commit() = 0;
 			boost::shared_ptr<MUCBookmark> createBookmarkFromForm();
 		public slots:
 			void accept();
diff --git a/Swift/QtUI/QtEditBookmarkWindow.cpp b/Swift/QtUI/QtEditBookmarkWindow.cpp
index 016f17e..76a01f6 100644
--- a/Swift/QtUI/QtEditBookmarkWindow.cpp
+++ b/Swift/QtUI/QtEditBookmarkWindow.cpp
@@ -6,13 +6,22 @@
 
 #include "QtEditBookmarkWindow.h"
 
+#include "QtSwiftUtil.h"
+
 namespace Swift {
 QtEditBookmarkWindow::QtEditBookmarkWindow(UIEventStream* eventStream, boost::shared_ptr<MUCBookmark> bookmark) : eventStream_(eventStream), bookmark_(bookmark) {
-
+	name_->setText(P2QSTRING(bookmark->getName()));
+	room_->setText(P2QSTRING(bookmark->getRoom().toString()));
+	autojoin_->setChecked(bookmark->getAutojoin());
+	nick_->setText(bookmark->getNick() ? P2QSTRING(bookmark->getNick().get()) : "");
+	password_->setText(bookmark->getPassword() ? P2QSTRING(bookmark->getPassword().get()) : "");
 }
 
-void QtEditBookmarkWindow::commit() {
-	eventStream_->send(boost::shared_ptr<UIEvent>(new EditMUCBookmarkUIEvent(bookmark_, createBookmarkFromForm())));
+bool QtEditBookmarkWindow::commit() {
+	boost::shared_ptr<MUCBookmark> bookmark = createBookmarkFromForm();
+	if (!bookmark) return false;
+	eventStream_->send(boost::shared_ptr<UIEvent>(new EditMUCBookmarkUIEvent(bookmark_, bookmark)));
+	return true;
 }
 
 }
diff --git a/Swift/QtUI/QtEditBookmarkWindow.h b/Swift/QtUI/QtEditBookmarkWindow.h
index 3c11fbe..1ca5001 100644
--- a/Swift/QtUI/QtEditBookmarkWindow.h
+++ b/Swift/QtUI/QtEditBookmarkWindow.h
@@ -15,7 +15,7 @@ namespace Swift {
 		Q_OBJECT
 		public:
 			QtEditBookmarkWindow(UIEventStream* eventStream, boost::shared_ptr<MUCBookmark> bookmark);
-			void commit();
+			bool commit();
 	
 		private:
 			UIEventStream* eventStream_;
diff --git a/Swiften/MUC/MUCBookmarkManager.cpp b/Swiften/MUC/MUCBookmarkManager.cpp
index 72e63f2..f503754 100644
--- a/Swiften/MUC/MUCBookmarkManager.cpp
+++ b/Swiften/MUC/MUCBookmarkManager.cpp
@@ -80,7 +80,6 @@ void MUCBookmarkManager::replaceBookmark(boost::shared_ptr<MUCBookmark> oldBookm
 }
 
 void MUCBookmarkManager::addBookmark(boost::shared_ptr<MUCBookmark> bookmark) {
-	std::cout << "adding bookmark with pointer " << bookmark.get() << std::endl;
 	bookmarks_.push_back(bookmark);
 	onBookmarkAdded(bookmark);
 	flush();
-- 
cgit v0.10.2-6-g49f6