#include #include "transfer_view.h" QString bytes_to_string(ULLINT s) { double p = (double)s; if (p<1024.*1024.*1024.) { if (p<1024.*1024.) { if (p<1024.) { return QString::number(p, 'f', 2) + " Byte"; } else return QString::number(p/1024., 'f', 2) + " KB"; } else return QString::number(p/(1024.*1024.), 'f', 2) + " MB"; } else return QString::number(p/(1024.*1024.*1024.), 'f', 2) + " GB"; } void transfer_lvi::set_column_type(const int column, const int ct) { if (column>=0 && column=0 && ct<=CT_EMPTY) column_type[column] = ct; } void transfer_lvi::set_layout(int lo, transfer_item *u) { layout = lo; gdl = 0; udl = u; udl->set_QLVI(this); this->setExpandable(false); for (int c=0; cset_QLVI(this); this->setExpandable(true); for (int c=0; cfilename() : (udl ? udl->filename() : QString::null); case CT_FSIZE: return gdl ? bytes_to_string(gdl->filesize()) : (udl?(udl->file_size ? bytes_to_string(udl->file_size):QString::null):QString::null); case CT_UNAME: if (gdl) { if (gdl->num_sources()==0) return QString("No sources"); else return QString::number(gdl->num_sources()) + (gdl->num_sources()>1 ? " users" : " user"); }else return (udl ? udl->user_name : QString::null); case CT_STATUS: { QString res = gdl ? gdl->status_str() : (udl ? udl->status_str() : QString::null); if ((res=="Downloading" || res=="Uploading") && layout!=Q_GDL && layout!=Q_GDL_SRC) { res += " (" + QString::number((double)(gdl ? gdl->progress() : udl->progress())*100., 'f', 1) + "%) "; } return res; } case CT_PROGRESS: // how much is left if (gdl) return bytes_to_string(gdl->recv_left()); else if (udl && r_len(udl->range) > 1) return bytes_to_string(r_len(udl->range) - udl->bytes_done); return QString::null; case CT_RATE: return gdl ? bytes_to_string((unsigned int)gdl->ETR())+"/s" : (udl ? bytes_to_string((unsigned int)udl->bps())+"/s" : QString::null); case CT_ETA: { int s=-1; if (gdl) { s = gdl->ETC(); } else if (udl) { if (udl->bps() > 0) s = (r_len(udl->range) - udl->bytes_done)/udl->bps(); } else return QString::null; if (s==-1) return QString::null; int h=s/3600, m=(s/60) % 60; s = s%60; QString res(""); res += (h<10 ? "0"+QString::number(h) : QString::number(h)); res += (m<10 ? ":0" : ":") + QString::number(m); res += (s<10 ? ":0" : ":") + QString::number(s); return res; } case CT_TARGET: if (!gdl) return QString::null; if (gdl->get_target_directory().isEmpty()) return QString("Default"); else return gdl->get_target_directory(); case CT_EMPTY: default: return QString::null; } } void transfer_lvi::paintCell ( QPainter * p, const QColorGroup & cg, int column, int width, int align ) { // Do we need to draw a progress bar at all? bool draw_bar = gdl ? gdl->status_str() == "Downloading" : (udl ? (udl->status_str() == "Downloading" || udl->status_str() == "Uploading") : false); draw_bar = draw_bar && column_type[column] == CT_STATUS && layout!=Q_GDL && layout!=Q_GDL_SRC; if (!draw_bar) QListViewItem::paintCell( p, cg, column, width, align ); else { int w=width, h=height(); // complete/complete highlight/incomplete range, outer/inner border QColor done = QColor(50,50,100); QColor high0 = QColor(80,80,180); QColor high = QColor(100,100,200); QColor high2 = QColor(120,120,240); QColor left = QColor(255,255,255); QColor left2 = QColor(235,235,255); QColor border1 = QColor(20,20,20); QColor border2 = QColor(200,200,200); QColor border2s = QColor(80,80,100); // Fill cell with background p->setBrush(QBrush(isSelected() ? cg.highlight() : cg.base(), Qt::SolidPattern)); p->setPen(NoPen); p->drawRect( 0, 0, w, h ); if (w>=3) { // Draw unfilled outer border p->setBrush(Qt::NoBrush); if (isSelected()) p->setPen(QPen(border2s, 1)); else p->setPen(QPen(border2, 1)); p->drawRect( 1, 1, w-2, h-2); if (w>=6) { // Draw inner border p->setPen(QPen(border1, 1)); p->setBrush(Qt::NoBrush); p->drawRect( 2, 2, w-4, h-4); // Draw progress bar itself if (w>=9) { float progress = gdl ? gdl->progress() : (udl ? udl->progress() : .0f); int y1 = 4; int h1 = (h-8)/3; int y2 = y1+h1; int h2 = (h-8)-h1*2; int y3 = y2+h2; int x1 = 4; int w1 = (int)((w-6)*progress)-2; int x2 = 3 + (int)((w-6)*progress); int w2 = w - x2 - 3; // draw dark outline p->setPen(QPen(done, 1)); p->setBrush(Qt::NoBrush); p->drawRect( 3, 3,(int)((w-6)*progress), h-6 ); // fill the "complete" range p->setPen(NoPen); p->setBrush(QBrush(high0, Qt::SolidPattern)); p->drawRect( x1, y1, w1, h1 ); p->setBrush(QBrush(high, Qt::SolidPattern)); p->drawRect( x1, y2, w1, h2 ); p->setBrush(QBrush(high2, Qt::SolidPattern)); p->drawRect( x1, y3, w1, h1 ); // fill the "incomplete" range p->setBrush(QBrush(isSelected() ? left2 : left, Qt::SolidPattern)); p->drawRect( x2, 3, w2, h-6 ); } // Status text shadow p->setPen(QPen(QColor(5,5,5), 2)); p->drawText(5,1, w-4, h, align, text(column), -1); // Status text foreground p->setPen(QPen(QColor(250,250,255), 1)); p->drawText(4,0, w-4, h, align, text(column), -1); } } } } /* * * $Log: transfer_view.cc,v $ * Revision 1.5 2004/07/25 21:09:35 estrato * adjusted dl resume delay and dl items display * * Revision 1.4 2004/02/22 06:48:53 estrato * Bugfixes, cleaning up * * Revision 1.3 2003/08/18 12:19:43 estrato * Old transfer dialog now completely replaced, but some functionality is gone. Will add complete functionality in next commit. * * Revision 1.2 2003/08/16 21:34:19 estrato * New transfer dialog update, almost all internal functions done. Will replaceold transferdlg in next commit. * * Revision 1.1 2003/08/14 23:30:45 estrato * New transfer widget, basic storage and view functionality, no signals connected yet. * * */