00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "FileItem.h"
00019
00020 #include <qlistview.h>
00021 #include <qpixmap.h>
00022
00023 #include "FileWindow.h"
00024
00025
00026 #include "images/folder.xpm"
00027 #include "images/lfolder.xpm"
00028 #include "images/folder_locked.xpm"
00029 #include "images/mpg.xpm"
00030 #include "images/lmpg.xpm"
00031 #include "images/unknown.xpm"
00032 #include "images/lunknown.xpm"
00033 #include "images/xml.xpm"
00034 #include "images/lxml.xpm"
00035 #include "images/browser.xpm"
00036 #include "images/lbrowser.xpm"
00037 #include "images/related_media.xpm"
00038 #include "images/zip_file.xpm"
00039 #include "images/lzip_file.xpm"
00040 #include "images/file_broken.xpm"
00041
00042 FileItem::FileItem( QListView *parent, QString fileName, int type,
00043 bool UseVideoRate )
00044 : QListViewItem( parent )
00045 {
00046 setUpData( fileName, type, UseVideoRate );
00047 }
00048
00049 FileItem::FileItem( QListViewItem *parent, QString fileName, int type,
00050 bool UseVideoRate )
00051 : QListViewItem( parent )
00052 {
00053 setUpData( fileName, type, UseVideoRate );
00054 }
00055
00056 void FileItem::setUpData( QString fileName, int type, bool UseVideoRate )
00057 {
00058 this->fileName = fileName;
00059 this->type = type;
00060
00061 this->UseVideoRate = UseVideoRate;
00062 setDragEnabled( true );
00063
00064 QString label = fileName;
00065 if( fileName != "/" )
00066 label = fileName.section( "/", -1 );
00067 setText( COLUMN_FILENAME, label );
00068
00069 autoSetIcon();
00070 }
00071
00072 void FileItem::setProperties( QString owner, QString group,
00073 QString permissions,
00074 unsigned long long int size, QDateTime date,
00075 unsigned int VideoRate )
00076 {
00077 this->owner = owner;
00078 this->group = group;
00079 this->permissions = permissions;
00080 this->size = size;
00081 this->date = date;
00082 this->VideoRate = VideoRate;
00083
00084 setText( COLUMN_DATE, date.toString( Qt::LocalDate ) );
00085 setText( COLUMN_OWNER, owner );
00086 setText( COLUMN_GROUP, group );
00087 setText( COLUMN_SIZE, QString( RioExplorer::formatSize( size ) ) );
00088 setText( COLUMN_PERMISSIONS, permissions );
00089
00090 if( UseVideoRate )
00091 {
00092 if( getExtType() == FileItem::ICONID_MPG)
00093 setText( COLUMN_VIDEORATE, QString( "%1 Kbps" ).arg( VideoRate ) );
00094 else
00095 setText( COLUMN_VIDEORATE, QString( "-" ) );
00096 }
00097
00098 autoSetIcon();
00099 }
00100
00101 QString FileItem::getFileName( void )
00102 {
00103 return fileName;
00104 }
00105
00106 bool FileItem::isDir( void )
00107 {
00108 return ( ( type == ObjectInfo::FILE_TYPE_DIRECTORY ) ||
00109 ( type == ObjectInfo::FILE_TYPE_DIR_LINK ) );
00110 }
00111
00112 QString FileItem::getPermissions( void )
00113 {
00114 return permissions;
00115 }
00116
00117 bool FileItem::canRead( void )
00118 {
00119 return true;
00120 }
00121
00122 bool FileItem::isLink( void )
00123 {
00124 return ( ( type == ObjectInfo::FILE_TYPE_BROKEN_LINK ) ||
00125 ( type == ObjectInfo::FILE_TYPE_DIR_LINK ) ||
00126 ( type == ObjectInfo::FILE_TYPE_DATA_LINK ) );
00127 }
00128
00129 bool FileItem::isBrokenLink( void )
00130 {
00131 return ( type == ObjectInfo::FILE_TYPE_BROKEN_LINK );
00132 }
00133
00134 unsigned long long int FileItem::getSize( void )
00135 {
00136 return size;
00137 }
00138
00139 QDateTime FileItem::getDate( void )
00140 {
00141 return date;
00142 }
00143
00144 QString FileItem::getOwner( void )
00145 {
00146 return owner;
00147 }
00148
00149 QString FileItem::getGroup( void )
00150 {
00151 return group;
00152 }
00153
00154 unsigned int FileItem::getExtType( void )
00155 {
00156 unsigned int ext;
00157 if( isDir() )
00158 {
00159 if( canRead() )
00160 {
00161 if( isLink() )
00162 {
00163 if( isBrokenLink() )
00164 ext = ICONID_BROKEN_LINK;
00165 else
00166 ext = ICONID_DIR_LINK;
00167 }
00168 else
00169 ext = ICONID_DIRECTORY;
00170 }
00171 else
00172 ext = ICONID_LOCKED_DIRECTORY;
00173 }
00174 else
00175 {
00176 QString ext_str;
00177
00178 ext_str = fileName.section( ".", -1 );
00179
00180 if( isLink() )
00181 {
00182 if( isBrokenLink() )
00183 ext = ICONID_BROKEN_LINK;
00184 else if( ( ext_str == "mpg" ) || ( ext_str == "mpeg" ) )
00185 ext = ICONID_MPG_LINK;
00186 else if( ext_str == "xml" )
00187 ext = ICONID_XML_LINK;
00188 else if( ext_str == "browser" )
00189 ext = ICONID_BROWSER_LINK;
00190 else if( ( ext_str == "zip" ) || ( ext_str == "gz" ) )
00191 ext = ICONID_ZIP_FILE_LINK;
00192 else
00193 ext = ICONID_UNKNOWN_FILE_LINK;
00194 }
00195 else
00196 {
00197 if( ( ext_str == "mpg" ) || ( ext_str == "mpeg" ) )
00198 ext = ICONID_MPG;
00199 else if( ext_str == "xml" )
00200 ext = ICONID_XML;
00201 else if( ext_str == "browser" )
00202 ext = ICONID_BROWSER;
00203 else if( ext_str == "index" )
00204 ext = ICONID_INDEX;
00205 else if( ext_str == "tgif" )
00206 ext = ICONID_TGIF;
00207 else if( ( ext_str == "zip" ) || ( ext_str == "gz" ) )
00208 ext = ICONID_ZIP_FILE;
00209 else
00210 ext = ICONID_UNKNOWN_FILE;
00211 }
00212 }
00213
00214 return ext;
00215 }
00216
00217 int FileItem::getType( void )
00218 {
00219 return ((FileWindow *)listView())->getType();
00220 }
00221
00222 QString FileItem::getPath( void )
00223 {
00224 QString path;
00225
00226 if( !isDir() )
00227 {
00228 int index = fileName.findRev( '/' );
00229 path = fileName.left( index );
00230 }
00231 else
00232 path = fileName;
00233
00234 return path;
00235 }
00236
00237 void FileItem::autoSetIcon( void )
00238 {
00239 switch( getExtType() )
00240 {
00241 case ICONID_DIRECTORY:
00242 setPixmap( 0, QPixmap( (const char **) image_folder ) );
00243 break;
00244 case ICONID_DIR_LINK:
00245 setPixmap( 0, QPixmap( (const char **) image_lfolder ) );
00246 break;
00247 case ICONID_LOCKED_DIRECTORY:
00248 setPixmap( 0, QPixmap( (const char **) image_folder_locked ) );
00249 break;
00250 case ICONID_UNKNOWN_FILE:
00251 setPixmap( 0, QPixmap( (const char **) image_unknown_file ) );
00252 break;
00253 case ICONID_UNKNOWN_FILE_LINK:
00254 setPixmap( 0, QPixmap( (const char **) image_lunknown_file ) );
00255 break;
00256 case ICONID_MPG:
00257 setPixmap( 0, QPixmap( (const char **) image_mpg ) );
00258 break;
00259 case ICONID_MPG_LINK:
00260 setPixmap( 0, QPixmap( (const char **) image_lmpg ) );
00261 break;
00262 case ICONID_XML:
00263 setPixmap( 0, QPixmap( (const char **) image_xml ) );
00264 break;
00265 case ICONID_XML_LINK:
00266 setPixmap( 0, QPixmap( (const char **) image_lxml ) );
00267 break;
00268 case ICONID_BROWSER:
00269 setPixmap( 0, QPixmap( (const char **) image_browser ) );
00270 break;
00271 case ICONID_BROWSER_LINK:
00272 setPixmap( 0, QPixmap( (const char **) image_lbrowser ) );
00273 break;
00274 case ICONID_INDEX:
00275 setPixmap( 0, QPixmap( (const char **) image_related_media ) );
00276 break;
00277 case ICONID_ZIP_FILE:
00278 setPixmap( 0, QPixmap( (const char **) image_zip_file ) );
00279 break;
00280 case ICONID_ZIP_FILE_LINK:
00281 setPixmap( 0, QPixmap( (const char **) image_lzip_file ) );
00282 break;
00283 case ICONID_TGIF:
00284 setPixmap( 0, QPixmap( (const char **) image_related_media ) );
00285 break;
00286 case ICONID_RELATED_MEDIA:
00287 setPixmap( 0, QPixmap( (const char **) image_related_media ) );
00288 break;
00289 case ICONID_BROKEN_LINK:
00290 setPixmap( 0, QPixmap( (const char **) image_file_broken ) );
00291 break;
00292 }
00293 }
00294
00295 CRioSession * FileItem::getSession( void )
00296 {
00297 CRioSession * session;
00298 if( getType() == FileWindow::RIO )
00299 {
00300 session = ((FileWindow *)listView())->getSession();
00301 }
00302 else
00303 session = NULL;
00304
00305 return session;
00306 }
00307
00308 bool FileItem::getPathUntil( unsigned maxCount,
00309 QString orignPath,
00310 QString *destPath )
00311 {
00312 *destPath = orignPath.section( "/", 1, maxCount,
00313 QString::SectionIncludeLeadingSep );
00314
00315 return !(*destPath).isEmpty();
00316 }
00317
00318
00319
00320
00321
00322
00323 int FileItem::compare( QListViewItem *item, int column, bool ascending ) const
00324 {
00325 FileItem *other_item = (FileItem *)item;
00326
00327
00328 if( column == (int)COLUMN_SIZE )
00329 {
00330 return size - other_item->getSize();
00331 }
00332 else if( column == (int)COLUMN_DATE )
00333 {
00334 return other_item->getDate().secsTo( date );
00335 }
00336 else
00337 {
00338 return QListViewItem::compare( item, column, ascending );
00339 }
00340 }