2 This file is part of Faster Application Manager.
4 Faster Application Manager is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 Faster Application Manager is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with Faster Application Manager. If not, see <http://www.gnu.org/licenses/>.
17 (C) Heikki Holstila 2010
21 #include "repository.h"
23 #include "aaptinterface.h"
25 Repository::Repository(): iEnabled(false)
29 Repository::~Repository()
33 QString Repository::toString() const
41 str += iUrl + iDir + " " + iDist;
42 if( !iComponents.isEmpty() )
43 str += " " + iComponents;
45 return( str.trimmed() );
48 QStringList Repository::toListFileNames() const
52 QStringList com = iComponents.split(' ');
56 for( int i=0; i<com.count(); i++ ) {
57 QString chopUrl = iUrl.mid( iUrl.indexOf("://")+3 );
58 if( !com.at(i).isEmpty() )
62 QString str = chopUrl + iDir + disttext + iDist + "_" + com.at(i);
63 if( !com.at(i).isEmpty() )
64 str += "_binary-armel_Packages";
68 str.replace("___","_");
69 str.replace("__","_");
76 bool Repository::setFromString(QString repo)
78 QStringList parts = repo.trimmed().split(' ');
79 if( parts.count() < 3 )
82 if( parts.at(0) == "deb" ) {
84 } else if( parts.at(0) == "#deb" ) {
90 if( parts.at(1).indexOf("://") == -1 )
92 int d = parts.at(1).indexOf('/', parts.at(1).indexOf("://")+3 );
97 iUrl = parts.at(1).left(d+1);
98 iDir = parts.at(1).right( parts.at(1).length()-d-1 );
101 if( !parts.at(2).isEmpty() )
107 if( parts.count()>3 ) {
108 for(int i=3; i<parts.count(); i++)
109 iComponents += parts.at(i) + " ";
110 iComponents = iComponents.trimmed();
115 iName = iName.replace('/',' ').trimmed();
116 } else if( iDist != "" ) {
118 iName = iName.replace('/',' ').trimmed();
124 qDebug() << repo << "\n"
129 << iComponents << "\n"
131 << toString() << "\n"; */
133 set( iName, iUrl, iDir, iDist, iComponents, iEnabled ); // performs further sanity checks
138 void Repository::set(QString name, QString url_dir, QString dist, QString components, bool enabled)
143 if( url_dir.indexOf("://") == -1 )
145 int d = url_dir.indexOf('/', url_dir.indexOf("://")+3 );
150 url = url_dir.left(d+1);
151 dir = url_dir.right( url_dir.length()-d-1 );
154 set( name, url, dir, dist, components, enabled );
157 void Repository::set(QString name, QString url, QString dir, QString dist, QString components, bool enabled)
159 iName = name.trimmed();
160 iUrl = url.trimmed();
161 if( !iUrl.contains("://") )
162 iUrl.prepend("http://");
163 if( !iUrl.endsWith('/') )
165 iDir = dir.trimmed();
166 if( !iDir.endsWith('/') && !iDir.isEmpty() )
168 iDist = dist.trimmed();
169 iComponents = components.trimmed();
172 if( iDist.isEmpty() )
175 // ensure that the protocol part of the URL is lowercase
176 int pos = iUrl.indexOf("://");
177 QString proto = iUrl.left(pos);
178 iUrl = proto.toLower() + iUrl.mid(pos);