1 //=============================================================================
2 // MuseScore
3 // Linux Music Score Editor
4 //
5 // Copyright (C) 2002-2011 Werner Schweer and others
6 //
7 // This program is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License version 2.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 //=============================================================================
19
20 #include "pathlistdialog.h"
21 #include "preferences.h"
22 #include "musescore.h"
23
24 namespace Ms {
25
26 //---------------------------------------------------------
27 // PathListDialog
28 //---------------------------------------------------------
29
PathListDialog(QWidget * parent)30 PathListDialog::PathListDialog(QWidget* parent)
31 : QDialog(parent)
32 {
33 setObjectName("PathListDialog");
34 setupUi(this);
35 setWindowFlags(this->windowFlags() & ~Qt::WindowContextHelpButtonHint);
36
37 connect(add, SIGNAL(clicked()), SLOT(addClicked()));
38 connect(remove, SIGNAL(clicked()), SLOT(removeClicked()));
39
40 MuseScore::restoreGeometry(this);
41 }
42
43
44 //---------------------------------------------------------
45 // addClicked
46 //---------------------------------------------------------
47
addClicked()48 void PathListDialog::addClicked()
49 {
50 #if defined(WIN_PORTABLE)
51 QString dir = QDir::cleanPath(QString("%1/../../../Data/%2").arg(QCoreApplication::applicationDirPath()).arg(QCoreApplication::applicationName()));
52 #else
53 QString dir = QString("%1/%2").arg(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation)).arg(QCoreApplication::applicationName());
54 #endif
55
56 QString newPath = QFileDialog::getExistingDirectory(
57 this,
58 tr("Choose a directory"),
59 dir,
60 QFileDialog::ShowDirsOnly | (preferences.getBool(PREF_UI_APP_USENATIVEDIALOGS) ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog)
61 );
62 if (!newPath.isEmpty()) {
63 newPath = QDir(newPath).absolutePath();
64 if(files->findItems(newPath, Qt::MatchExactly).size() == 0)
65 files->addItem(newPath);
66 }
67 }
68
69 //---------------------------------------------------------
70 // removeClicked
71 //---------------------------------------------------------
72
removeClicked()73 void PathListDialog::removeClicked()
74 {
75 int n = files->currentRow();
76 if (n == -1)
77 return;
78 files->takeItem(n);
79 }
80
81 //---------------------------------------------------------
82 // path
83 //---------------------------------------------------------
path()84 QString PathListDialog::path()
85 {
86 int n = files->count();
87 QStringList sl;
88 for (int i = 0; i < n; ++i) {
89 QListWidgetItem* item = files->item(i);
90 sl.append(item->text());
91 }
92 return sl.join(";");
93 }
94
95 //---------------------------------------------------------
96 // setPath
97 //---------------------------------------------------------
setPath(QString path)98 void PathListDialog::setPath(QString path)
99 {
100 QStringList pl = path.split(";");
101 files->addItems(pl);
102 }
103
104 //---------------------------------------------------------
105 // hideEvent
106 //---------------------------------------------------------
107
hideEvent(QHideEvent * event)108 void PathListDialog::hideEvent(QHideEvent* event)
109 {
110 MuseScore::saveGeometry(this);
111 QWidget::hideEvent(event);
112 }
113
114 }
115
116