#include <QPushButton>
// Construct the class.
-AddBookmarkDialog::AddBookmarkDialog(const QString &bookmarkName, const QString &bookmarkUrl, const QIcon &favoriteIcon) : QDialog(nullptr)
+AddBookmarkDialog::AddBookmarkDialog(const QString &bookmarkName, const QString &bookmarkUrl, const QIcon &favoriteIcon, const double parentFolderId) : QDialog(nullptr)
{
// Set the window title.
setWindowTitle(i18nc("The add bookmark dialog window title.", "Add Bookmark"));
// Set the window modality.
setWindowModality(Qt::WindowModality::ApplicationModal);
- // Instantiate the bookmarks dialog UI.
+ // Instantiate the add bookmark dialog UI.
Ui::AddBookmarkDialog addBookmarkDialogUi;
// Setup the UI.
// Get handles for the widgets.
defaultFavoriteIconRadioButtonPointer = addBookmarkDialogUi.defaultFavoriteIconRadioButton;
customFavoriteIconRadioButtonPointer = addBookmarkDialogUi.customFavoriteIconRadioButton;
- bookmarkNamePointer = addBookmarkDialogUi.bookmarkNameLineEdit;
- bookmarkUrlPointer = addBookmarkDialogUi.bookmarkUrlLineEdit;
+ parentFolderTreeWidgetPointer = addBookmarkDialogUi.parentFolderTreeWidget;
+ bookmarkNameLineEditPointer = addBookmarkDialogUi.bookmarkNameLineEdit;
+ bookmarkUrlLineEditPointer = addBookmarkDialogUi.bookmarkUrlLineEdit;
QPushButton *browseButtonPointer = addBookmarkDialogUi.browseButton;
QDialogButtonBox *dialogButtonBoxPointer = addBookmarkDialogUi.dialogButtonBox;
// Set the default favorite icon.
defaultFavoriteIconRadioButtonPointer->setIcon(favoriteIcon);
+ // Instantiate a folder helper.
+ folderHelperPointer = new FolderHelper();
+
+ // Set the parent folder tree widget column count.
+ parentFolderTreeWidgetPointer->setColumnCount(2);
+
+ // Hide the second column.
+ parentFolderTreeWidgetPointer->hideColumn(folderHelperPointer->FOLDER_ID_COLUMN);
+
+ // Set the column header.
+ parentFolderTreeWidgetPointer->setHeaderLabel(i18nc("The folder tree widget header", "Select Parent Folder"));
+
+ // Create a bookmarks tree widget item.
+ QTreeWidgetItem *bookmarksTreeWidgetItemPointer = new QTreeWidgetItem();
+
+ // Populate the bookmarks tree widget item.
+ bookmarksTreeWidgetItemPointer->setText(folderHelperPointer->FOLDER_NAME_COLUMN, i18nc("The bookmarks root tree widget name", "Bookmarks"));
+ bookmarksTreeWidgetItemPointer->setIcon(folderHelperPointer->FOLDER_NAME_COLUMN, QIcon::fromTheme("bookmarks"));
+ bookmarksTreeWidgetItemPointer->setText(folderHelperPointer->FOLDER_ID_COLUMN, QLatin1String("0"));
+
+ // Add the bookmarks tree widget item to the root of the tree.
+ parentFolderTreeWidgetPointer->addTopLevelItem(bookmarksTreeWidgetItemPointer);
+
+ // Select the root bookmarks folder if it is the initial parent folder.
+ if (parentFolderId == 0)
+ bookmarksTreeWidgetItemPointer->setSelected(true);
+
+ // Populate the subfolders.
+ folderHelperPointer->populateSubfolders(bookmarksTreeWidgetItemPointer, parentFolderId);
+
+ // Open all the folders.
+ parentFolderTreeWidgetPointer->expandAll();
+
// Populate the line edits.
- bookmarkNamePointer->setText(bookmarkName);
- bookmarkUrlPointer->setText(bookmarkUrl);
+ bookmarkNameLineEditPointer->setText(bookmarkName);
+ bookmarkUrlLineEditPointer->setText(bookmarkUrl);
// Scroll to the beginning of the line edits.
- bookmarkNamePointer->setCursorPosition(0);
- bookmarkUrlPointer->setCursorPosition(0);
+ bookmarkNameLineEditPointer->setCursorPosition(0);
+ bookmarkUrlLineEditPointer->setCursorPosition(0);
// Add buttons to the dialog button box.
- QPushButton *addBookmarkButtonPointer = dialogButtonBoxPointer->addButton(i18nc("The add bookmark button", "Add"), QDialogButtonBox::AcceptRole);
+ addButtonPointer = dialogButtonBoxPointer->addButton(i18nc("The add bookmark button", "Add"), QDialogButtonBox::AcceptRole);
// Set the button icons.
- addBookmarkButtonPointer->setIcon(QIcon::fromTheme("list-add"));
+ addButtonPointer->setIcon(QIcon::fromTheme("list-add"));
// Connect the buttons.
connect(browseButtonPointer, SIGNAL(clicked()), this, SLOT(browse()));
connect(dialogButtonBoxPointer, SIGNAL(accepted()), this, SLOT(addBookmark()));
connect(dialogButtonBoxPointer, SIGNAL(rejected()), this, SLOT(reject()));
+
+ // Update the UI when the line edits change.
+ connect(bookmarkNameLineEditPointer, SIGNAL(textEdited(const QString&)), this, SLOT(updateUi()));
+ connect(bookmarkUrlLineEditPointer, SIGNAL(textEdited(const QString&)), this, SLOT(updateUi()));
+
+ // Set the initial UI status.
+ updateUi();
}
void AddBookmarkDialog::addBookmark()
{
+ // Get the selected folders list.
+ QList<QTreeWidgetItem*> selectedFoldersList = parentFolderTreeWidgetPointer->selectedItems();
+
+ // Get the selected folder.
+ QTreeWidgetItem *selectedFolderPointer = selectedFoldersList.first();
+
// Get the favorite icon.
QIcon favoriteIcon = defaultFavoriteIconRadioButtonPointer->isChecked() ? defaultFavoriteIconRadioButtonPointer->icon() : customFavoriteIconRadioButtonPointer->icon();
BookmarkStruct *bookmarkStructPointer = new BookmarkStruct;
// Populate the bookmark struct.
- bookmarkStructPointer->bookmarkName = bookmarkNamePointer->text();
- bookmarkStructPointer->bookmarkUrl = bookmarkUrlPointer->text();
+ bookmarkStructPointer->name = bookmarkNameLineEditPointer->text();
+ bookmarkStructPointer->url = bookmarkUrlLineEditPointer->text();
+ bookmarkStructPointer->parentFolderId = selectedFolderPointer->text(folderHelperPointer->FOLDER_ID_COLUMN).toDouble();
bookmarkStructPointer->favoriteIcon = favoriteIcon;
// Add the bookmark.
customFavoriteIconRadioButtonPointer->setChecked(true);
}
}
+
+void AddBookmarkDialog::updateUi()
+{
+ // Determine if both line edits are populated.
+ if (bookmarkNameLineEditPointer->text().isEmpty() || bookmarkUrlLineEditPointer->text().isEmpty()) // At least one of the line edits is empty.
+ {
+ // Disable the add button.
+ addButtonPointer->setEnabled(false);
+ }
+ else // Both of the line edits are populated.
+ {
+ // Enable the add button.
+ addButtonPointer->setEnabled(true);
+ }
+}