author | drw <drw> | 2003-04-29 02:28:16 (UTC) |
---|---|---|
committer | drw <drw> | 2003-04-29 02:28:16 (UTC) |
commit | e096c9d1f2be1ec74ede583fc4221871a56ef508 (patch) (unidiff) | |
tree | 1c6f49430179e2f262179951477bbe4bd7d32e71 /noncore/settings/aqpkg/utils.cpp | |
parent | 2f26f696ca6acd05aa615e15d891eede9907a1c0 (diff) | |
download | opie-e096c9d1f2be1ec74ede583fc4221871a56ef508.zip opie-e096c9d1f2be1ec74ede583fc4221871a56ef508.tar.gz opie-e096c9d1f2be1ec74ede583fc4221871a56ef508.tar.bz2 |
Give aqpkg standard source headers and some minor code clean-up.
Diffstat (limited to 'noncore/settings/aqpkg/utils.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/aqpkg/utils.cpp | 47 |
1 files changed, 28 insertions, 19 deletions
diff --git a/noncore/settings/aqpkg/utils.cpp b/noncore/settings/aqpkg/utils.cpp index 446ce39..00607dd 100644 --- a/noncore/settings/aqpkg/utils.cpp +++ b/noncore/settings/aqpkg/utils.cpp | |||
@@ -1,96 +1,105 @@ | |||
1 | /*************************************************************************** | 1 | /* |
2 | utils.cpp - description | 2 | This file is part of the OPIE Project |
3 | ------------------- | 3 | |
4 | begin : Sat Sep 7 2002 | 4 | =. Copyright (c) 2002 Andy Qua <andy.qua@blueyonder.co.uk> |
5 | copyright : (C) 2002 by Andy Qua | 5 | .=l. Dan Williams <drw@handhelds.org> |
6 | email : andy.qua@blueyonder.co.uk | 6 | .>+-= |
7 | ***************************************************************************/ | 7 | _;:, .> :=|. This file is free software; you can |
8 | 8 | .> <`_, > . <= redistribute it and/or modify it under | |
9 | /*************************************************************************** | 9 | :`=1 )Y*s>-.-- : the terms of the GNU General Public |
10 | * * | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | * This program is free software; you can redistribute it and/or modify * | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | * it under the terms of the GNU General Public License as published by * | 12 | ._= =} : or (at your option) any later version. |
13 | * the Free Software Foundation; either version 2 of the License, or * | 13 | .%`+i> _;_. |
14 | * (at your option) any later version. * | 14 | .i_,=:_. -<s. This file is distributed in the hope that |
15 | * * | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | ***************************************************************************/ | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General | ||
19 | ..}^=.= = ; Public License for more details. | ||
20 | ++= -. .` .: | ||
21 | : = ...= . :.=- You should have received a copy of the GNU | ||
22 | -. .:....=;==+<; General Public License along with this file; | ||
23 | -_. . . )=. = see the file COPYING. If not, write to the | ||
24 | -- :-=` Free Software Foundation, Inc., | ||
25 | 59 Temple Place - Suite 330, | ||
26 | Boston, MA 02111-1307, USA. | ||
27 | |||
28 | */ | ||
17 | 29 | ||
18 | #include <stdio.h> | 30 | #include <stdio.h> |
19 | #include <sys/vfs.h> | 31 | #include <sys/vfs.h> |
20 | //#include <mntent.h> | ||
21 | 32 | ||
22 | #include "utils.h" | 33 | #include "utils.h" |
23 | #include "global.h" | 34 | #include "global.h" |
24 | 35 | ||
25 | Utils :: Utils() | 36 | Utils :: Utils() |
26 | { | 37 | { |
27 | } | 38 | } |
28 | 39 | ||
29 | Utils :: ~Utils() | 40 | Utils :: ~Utils() |
30 | { | 41 | { |
31 | } | 42 | } |
32 | 43 | ||
33 | |||
34 | QString Utils :: getPathfromIpkFilename( const QString &file ) | 44 | QString Utils :: getPathfromIpkFilename( const QString &file ) |
35 | { | 45 | { |
36 | int p = file.findRev( "/" ); | 46 | int p = file.findRev( "/" ); |
37 | QString path = ""; | 47 | QString path = ""; |
38 | if ( p != -1 ) | 48 | if ( p != -1 ) |
39 | path = file.left( p ); | 49 | path = file.left( p ); |
40 | 50 | ||
41 | return path; | 51 | return path; |
42 | 52 | ||
43 | } | 53 | } |
44 | 54 | ||
45 | QString Utils :: getFilenameFromIpkFilename( const QString &file ) | 55 | QString Utils :: getFilenameFromIpkFilename( const QString &file ) |
46 | { | 56 | { |
47 | int p = file.findRev( "/" ); | 57 | int p = file.findRev( "/" ); |
48 | QString name = file; | 58 | QString name = file; |
49 | if ( p != -1 ) | 59 | if ( p != -1 ) |
50 | name = name.mid( p + 1 ); | 60 | name = name.mid( p + 1 ); |
51 | 61 | ||
52 | 62 | ||
53 | return name; | 63 | return name; |
54 | } | 64 | } |
55 | 65 | ||
56 | QString Utils :: getPackageNameFromIpkFilename( const QString &file ) | 66 | QString Utils :: getPackageNameFromIpkFilename( const QString &file ) |
57 | { | 67 | { |
58 | int p = file.findRev( "/" ); | 68 | int p = file.findRev( "/" ); |
59 | QString name = file; | 69 | QString name = file; |
60 | if ( p != -1 ) | 70 | if ( p != -1 ) |
61 | name = name.mid( p + 1 ); | 71 | name = name.mid( p + 1 ); |
62 | p = name.find( "_" ); | 72 | p = name.find( "_" ); |
63 | QString packageName = name.mid( 0, p ); | 73 | QString packageName = name.mid( 0, p ); |
64 | return packageName; | 74 | return packageName; |
65 | } | 75 | } |
66 | 76 | ||
67 | QString Utils :: getPackageVersionFromIpkFilename( const QString &file ) | 77 | QString Utils :: getPackageVersionFromIpkFilename( const QString &file ) |
68 | { | 78 | { |
69 | int p = file.findRev( "/" ); | 79 | int p = file.findRev( "/" ); |
70 | QString name = file; | 80 | QString name = file; |
71 | if ( p != -1 ) | 81 | if ( p != -1 ) |
72 | name = name.mid( p + 1 ); | 82 | name = name.mid( p + 1 ); |
73 | p = name.find( "_" ) + 1; | 83 | p = name.find( "_" ) + 1; |
74 | int p2 = name.find( "_", p ); | 84 | int p2 = name.find( "_", p ); |
75 | QString version = name.mid( p, p2 - p ); | 85 | QString version = name.mid( p, p2 - p ); |
76 | return version; | 86 | return version; |
77 | } | 87 | } |
78 | 88 | ||
79 | 89 | ||
80 | bool Utils :: getStorageSpace( const char *path, long *blockSize, long *totalBlocks, long *availBlocks ) | 90 | bool Utils :: getStorageSpace( const char *path, long *blockSize, long *totalBlocks, long *availBlocks ) |
81 | { | 91 | { |
82 | bool ret = false; | 92 | bool ret = false; |
83 | 93 | ||
84 | // qDebug( "Reading from path %s", path ); | ||
85 | struct statfs fs; | 94 | struct statfs fs; |
86 | if ( !statfs( path, &fs ) ) | 95 | if ( !statfs( path, &fs ) ) |
87 | { | 96 | { |
88 | *blockSize = fs.f_bsize; | 97 | *blockSize = fs.f_bsize; |
89 | *totalBlocks = fs.f_blocks; | 98 | *totalBlocks = fs.f_blocks; |
90 | *availBlocks = fs.f_bavail; | 99 | *availBlocks = fs.f_bavail; |
91 | ret = true; | 100 | ret = true; |
92 | } | 101 | } |
93 | 102 | ||
94 | return ret; | 103 | return ret; |
95 | } | 104 | } |
96 | 105 | ||