| 1 | /* |
| 2 | * Copyright 2014 Mihai Niculescu <[email protected]> |
| 3 | * |
| 4 | * This file is part of EqualX Project (https://launchpad.net/equalx/) |
| 5 | * |
| 6 | * EqualX is free software: you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation, either version 3 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * EqualX is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | */ |
| 19 | |
| 20 | #include "Library/LibraryData.h" |
| 21 | #include "Library/Library.h" |
| 22 | |
| 23 | #include "DialogPreferencesBookmark.h" |
| 24 | #include "ui_DialogPreferencesBookmark.h" |
| 25 | |
| 26 | DialogPreferencesBookmark::DialogPreferencesBookmark(QWidget *parent) : |
| 27 | QDialog(parent), |
| 28 | ui(new Ui::DialogPreferencesBookmark), |
| 29 | mPIdx(0) |
| 30 | { |
| 31 | ui->setupUi(this); |
| 32 | } |
| 33 | |
| 34 | DialogPreferencesBookmark::~DialogPreferencesBookmark() |
| 35 | { |
| 36 | delete ui; |
| 37 | } |
| 38 | |
| 39 | QString DialogPreferencesBookmark::title() const |
| 40 | { |
| 41 | return ui->editTitle->text(); |
| 42 | } |
| 43 | |
| 44 | QString DialogPreferencesBookmark::description() const |
| 45 | { |
| 46 | return ui->editDescription->toPlainText(); |
| 47 | } |
| 48 | |
| 49 | int DialogPreferencesBookmark::parentFolder() const |
| 50 | { |
| 51 | int idx = ui->folderCombobox->currentIndex(); |
| 52 | |
| 53 | if(idx>1){ |
| 54 | return ui->folderCombobox->itemData(idx).toInt(); |
| 55 | } |
| 56 | |
| 57 | return 1; |
| 58 | } |
| 59 | |
| 60 | void DialogPreferencesBookmark::setTitle(const QString &title) |
| 61 | { |
| 62 | ui->editTitle->setText(title); |
| 63 | } |
| 64 | |
| 65 | void DialogPreferencesBookmark::setDescrition(const QString &desc) |
| 66 | { |
| 67 | ui->editDescription->setPlainText(desc); |
| 68 | } |
| 69 | |
| 70 | void DialogPreferencesBookmark::setParentFolder(int id) |
| 71 | { |
| 72 | mPIdx = id; |
| 73 | } |
| 74 | |
| 75 | void DialogPreferencesBookmark::show() |
| 76 | { |
| 77 | populateFolderCombobox(); |
| 78 | |
| 79 | QDialog::show(); |
| 80 | } |
| 81 | |
| 82 | int DialogPreferencesBookmark::exec() |
| 83 | { |
| 84 | populateFolderCombobox(); |
| 85 | |
| 86 | return QDialog::exec(); |
| 87 | } |
| 88 | |
| 89 | void DialogPreferencesBookmark::populateFolderCombobox() |
| 90 | { |
| 91 | ui->folderCombobox->clear(); |
| 92 | |
| 93 | ui->folderCombobox->addItem(tr("Unsorted Bookmarks")); |
| 94 | ui->folderCombobox->insertSeparator(1); |
| 95 | |
| 96 | LibraryRowsList foldersList = LibraryManager::Instance()->getAllBookmarkedFolders(); |
| 97 | |
| 98 | foreach(LibraryModelData folderData, foldersList){ |
| 99 | ui->folderCombobox->addItem(QIcon::fromTheme("folder", QIcon("://resources/icons/bookmarks/folder.png")), folderData.name, folderData.id); |
| 100 | } |
| 101 | |
| 102 | int curIdx = 0; |
| 103 | if(mPIdx>1) |
| 104 | curIdx = ui->folderCombobox->findData(mPIdx); |
| 105 | |
| 106 | ui->folderCombobox->setCurrentIndex(curIdx); |
| 107 | } |
| 108 |