bbsmount.cc

来自「蒙特卡洛仿真源代码很有参考价值要按照步骤进行操作」· CC 代码 · 共 1,127 行 · 第 1/3 页

CC
1,127
字号
const MountPoint &ToolWindow::GetMountPoint(const int mntidx) const{    return mount_points[mntidx];}const PIXMAP &ToolWindow::GetPixmaps(void) const{    return pixmap;}size_tToolWindow::GetMountPointsCount(void) const{    return mount_points.size();}MountPoint &ToolWindow::GetMountPoint(const int mntidx){    return mount_points[mntidx];}stringToolWindow::getTooltip(const string &format, const MountPoint &mp, bool actual_statfs) const{    string result, pformat;    char buffer[1024], unit = '\0', last_unit = '\0';    unsigned int counter;    bool was_percent = false;    is_statfs_filled = actual_statfs;    mount_point = mp.GetMountPoint();    for (counter = 0; counter < format.length(); counter++) {	if (was_percent) {	    was_percent = false;	    switch (format[counter]) {		case '0':		case '1':		case '2':		case '3':		case '4':		case '5':		case '6':		case '7':		case '8':		case '9':		case '.':		    pformat += format[counter];		    was_percent = true;		    break;		case 'B':		case 'k':		case 'M':		case 'G':   // units		    unit = format[counter];		    was_percent = true;		    break;		case 'u':   // used		    float used;		    if (!is_statfs_filled) {			if (STATFS(mp.GetMountPoint().c_str(), &tooltip_statfs) != 0)			    return string("Can't get filesystem info!");			is_statfs_filled = true;		    }		    pformat.insert(pformat.begin(), '%');		    pformat += 'f';		    used = (float)(tooltip_statfs.f_blocks - tooltip_statfs.f_bfree) * tooltip_statfs.f_bsize;		    switch (unit) {			case 'B':			    sprintf(buffer, pformat.c_str(), used);			    break;			case 'k':			    sprintf(buffer, pformat.c_str(), used / 1024);			    break;			case 'M':			    sprintf(buffer, pformat.c_str(), used / 1048576);			    break;			case 'G':			    sprintf(buffer, pformat.c_str(), used / 1073741824);			    break;			default:			    if (USE_LARGER_UNIT(used)) {				unit = 'k';				used /= 1024;			    }			    if (USE_LARGER_UNIT(used)) {				unit = 'M';				used /= 1024;			    }			    if (USE_LARGER_UNIT(used)) {				unit = 'G';				used /= 1024;			    }			    sprintf(buffer, pformat.c_str(), used);			    break;		    }		    last_unit = unit;		    result += buffer;		    break;		case 'f':   // free		    float free;		    if (!is_statfs_filled) {			if (STATFS(mp.GetMountPoint().c_str(), &tooltip_statfs) != 0)			    return string("Can't get filesystem info!");			is_statfs_filled = true;		    }		    pformat.insert(pformat.begin(), '%');		    pformat += 'f';		    free = (float)tooltip_statfs.f_bavail * tooltip_statfs.f_bsize;		    switch (unit) {			case 'B':			    sprintf(buffer, pformat.c_str(), free);			    break;			case 'k':			    sprintf(buffer, pformat.c_str(), free / 1024);			    break;			case 'M':			    sprintf(buffer, pformat.c_str(), free / 1048576);			    break;			case 'G':			    sprintf(buffer, pformat.c_str(), free / 1073741824);			    break;			default:			    if (USE_LARGER_UNIT(free)) {				unit = 'k';				free /= 1024;			    }			    if (USE_LARGER_UNIT(free)) {				unit = 'M';				free /= 1024;			    }			    if (USE_LARGER_UNIT(free)) {				unit = 'G';				free /= 1024;			    }			    sprintf(buffer, pformat.c_str(), free);			    break;		    }		    last_unit = unit;		    result += buffer;		    break;		case 't':   // total		    float total;		    if (!is_statfs_filled) {			if (STATFS(mp.GetMountPoint().c_str(), &tooltip_statfs) != 0)			    return string("Can't get filesystem info!");			is_statfs_filled = true;		    }		    pformat.insert(pformat.begin(), '%');		    pformat += 'f';		    total = (float)(tooltip_statfs.f_blocks - tooltip_statfs.f_bfree + tooltip_statfs.f_bavail) * tooltip_statfs.f_bsize;		    switch (unit) {			case 'B':			    sprintf(buffer, pformat.c_str(), total);			    break;			case 'k':			    sprintf(buffer, pformat.c_str(), total / 1024);			    break;			case 'M':			    sprintf(buffer, pformat.c_str(), total / 1048576);			    break;			case 'G':			    sprintf(buffer, pformat.c_str(), total / 1073741824);			    break;			default:			    if (USE_LARGER_UNIT(total)) {				unit = 'k';				total /= 1024;			    }			    if (USE_LARGER_UNIT(total)) {				unit = 'M';				total /= 1024;			    }			    if (USE_LARGER_UNIT(total)) {				unit = 'G';				total /= 1024;			    }			    sprintf(buffer, pformat.c_str(), total);			    break;		    }		    last_unit = unit;		    result += buffer;		    break;		case 'v':		    if (last_unit == 'k' || last_unit == 'M' || last_unit == 'G')			result += last_unit;		    break;		case 'U':   // used %		    if (!is_statfs_filled) {			if (STATFS(mp.GetMountPoint().c_str(), &tooltip_statfs) != 0)			    return string("Can't get filesystem info!");			is_statfs_filled = true;		    }		    pformat.insert(pformat.begin(), '%');		    pformat += 'f';		    sprintf(buffer, pformat.c_str(), 100.0 - (float)tooltip_statfs.f_bavail * 100/tooltip_statfs.f_blocks);		    result += buffer;		    break;		case 'F':   // free %		    if (!is_statfs_filled) {			if (STATFS(mp.GetMountPoint().c_str(), &tooltip_statfs) != 0)			    return string("Can't get filesystem info!");			is_statfs_filled = true;		    }		    pformat.insert(pformat.begin(), '%');		    pformat += 'f';		    sprintf(buffer, pformat.c_str(), (float)tooltip_statfs.f_bavail * 100/tooltip_statfs.f_blocks);		    result += buffer;		    break;		case 'd':   // description		    pformat.insert(pformat.begin(), '%');		    pformat += 's';		    sprintf(buffer, pformat.c_str(), mp.getDescription().c_str());		    result += buffer;		    break;		case 's':   // mount point		    pformat.insert(pformat.begin(), '%');		    pformat += 's';		    sprintf(buffer, pformat.c_str(), mp.GetMountPoint().c_str());		    result += buffer;		    break;		case 'e':   // last error		    pformat.insert(pformat.begin(), '%');		    pformat += 's';		    sprintf(buffer, pformat.c_str(), mp.getLastError().c_str());		    result += buffer;		    break;		default:		    result += format[counter];		    break;	    }	    if (!was_percent) {		pformat.erase();		unit = '\0';	    }	} else {	    if (format[counter] == '%')		was_percent = true;	    else		result += format[counter];	}    }    return result;}voidToolWindow::FreeAll(void){    vector<MyImage *>::iterator pointer = images.begin();    vector<MountWindow *>::iterator mwpointer = mount_windows.begin();        mount_points.clear();    commands.clear();    infotexts.clear();    for (; pointer != images.end(); pointer++)	delete *pointer;    images.clear();    for (; mwpointer != mount_windows.end(); mwpointer++)	delete *mwpointer;    mount_windows.clear();}voidToolWindow::rereadResources(void){    delete resource;    resource = new Resource(this);}voidToolWindow::configure(void){    vector<string>::const_iterator pointer, end;    XpmImage new_image;    int image_counter;    commands = resource->GetCommands();    infotexts = resource->getInfoTexts();    mount_points = resource->GetMountPoints();    pointer = resource->GetImages().begin();    end = resource->GetImages().end();        XpmCreateXpmImageFromData(notfound_xpm, &new_image, NULL);    SetImage(0, new MyImage(getXDisplay(), rootwin, &new_image));    XpmFreeXpmImage(&new_image);    image_counter = 1;    for (; pointer != end; pointer++) {	File imagefile(pointer->c_str(), resource->GetImagePrefix().c_str());	MyImage *my_new_image;	if (imagefile.Exist()) {#if DEBUG	    if (debug_level >= dbg_all_work)		printf("Loading Xpm image %s.\n", imagefile.GetPath());#endif /* DEBUG */	    if (XpmReadFileToXpmImage(imagefile.GetPath(), &new_image, NULL) != XpmSuccess) {		XpmCreateXpmImageFromData(notfound_xpm, &new_image, NULL);#if DEBUG		printf("Can't read image data from file %s!\n", imagefile.GetPath());#endif /* DEBUG */	    }	}	else {	    XpmCreateXpmImageFromData(notfound_xpm, &new_image, NULL);#if DEBUG	    printf("Can't find image file %s!\n", pointer->c_str());#endif /* DEBUG */	}		my_new_image = new MyImage(getXDisplay(), rootwin, &new_image);	SetImage(image_counter++, my_new_image);	XpmFreeXpmImage(&new_image);    }    resource->FreeAll();}/*Display *ToolWindow::GetDisplay(void){    return dpy;}*/Resource *ToolWindow::GetResources(void){    return resource;}WindowToolWindow::GetRootWindow(void){    return rootwin;}voidToolWindow::CreateWindow(const bool do_reconfigure){    XSetWindowAttributes attrib;    XWMHints wmhints;    unsigned long create_mask;    create_mask = CWBackPixmap | CWOverrideRedirect | CWCursor | CWEventMask;     drawarea.width = resource->app.column_width * resource->app.columns;    drawarea.height = resource->app.row_height * resource->app.rows;    rootgeometry.width = resource->app.column_width * resource->app.columns +	resource->frame.bevelWidth * 2 + (resource->app.columns - 1) * resource->app.button_padding;    rootgeometry.height = resource->app.row_height * resource->app.rows +	resource->frame.bevelWidth * 2 + (resource->app.rows - 1) * resource->app.button_padding;    if (resource->position.mask & XNegative) {	resource->position.x = getCurrentScreenInfo()->getWidth() + resource->position.x - rootgeometry.width;    }    if (resource->position.mask & YNegative) {	resource->position.y = getCurrentScreenInfo()->getHeight() + resource->position.y - rootgeometry.height;    }    if (withdrawn) {	attrib.override_redirect = False;	wmhints.initial_state = WithdrawnState;    }    else {	attrib.override_redirect = True;	wmhints.initial_state = NormalState;    }    attrib.background_pixmap = ParentRelative;    attrib.cursor = getSessionCursor();    attrib.event_mask = ButtonPressMask | ButtonReleaseMask | ExposureMask |

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?