Esempio n. 1
0
static void
title_column_func (GtkTreeViewColumn *column,
                   GtkCellRenderer *cell,
                   GtkTreeModel *model,
                   GtkTreeIter *iter,
                   gchar *data)
{
    Download *d;

    gtk_tree_model_get (model, iter, 0, &d, -1);
    if (d) {
        gchar *title = download_get_title (d);
        gint isize = download_get_size_total (d);
        gchar *size = size_to_string (isize);
        gchar *comp = size_to_string (download_get_size_completed (d));

        gchar *str;
        if (isize != -1) {
            str = g_strdup_printf ("%s\n%s of %s", title, comp, size);
        } else {
            str = g_strdup_printf ("%s\n%s", title, comp);
        }

        g_object_set (G_OBJECT (cell), "text", str, NULL);
        g_free (size);
        g_free (comp);
        g_free (str);
    } else {
        g_object_set (G_OBJECT (cell), "text", "", NULL);
    }
}
Esempio n. 2
0
const TCHAR* CDriveInfo::as_text (int i)
{
	static CString tmpStr;
	switch (i)
	{
		case 0:
			return m_Name;
		case 1:
			return m_Type;
			
		case 2:
			if (m_TotalSize)
			{
				tmpStr = size_to_string (m_TotalSize);
				return 	(LPCTSTR)  tmpStr;		
			}
			else
				return EMPTYSTR;

		case 3:
			if (m_TotalSize)
			{
				tmpStr = size_to_string (m_FreeSpace);		
				return 	(LPCTSTR)  tmpStr;
			}
			else
				return EMPTYSTR;
		
		default:
			return EMPTYSTR;			
	}	
}
Esempio n. 3
0
QVariant NRemoteFSBrowser::data ( const QModelIndex & index, int role ) const
{
  QVariant data;

  if( index.isValid() )
  {
    FileInfo * item = m_data.at(index.row());

    if( role == Qt::DisplayRole )
    {
      switch( index.column() )
      {
      case 0:                     // item name
        data = item->name;
        break;

      case 1:                      // size (in case it's a file)
        data = is_file(index) ? size_to_string(item->file_size) : QString();
        break;

      case 2:                      // date modified
        data = item->date_modified;
        break;
      }
    }
    else if( role == Qt::TextAlignmentRole && index.column() == 1)
      return Qt::AlignRight;
    else if( role == Qt::ToolTipRole )
    {
      if(item->type == FILE)
        return QString("Size: %1\nDate modified: %2")
            .arg(size_to_string(item->file_size)).arg(item->date_modified);
      else
        return QString("Date modified: %1").arg(item->date_modified);
    }
  }

  return data;
}
Esempio n. 4
0
BOOL CCharts::OnInitDialog()
{
	CDialog::OnInitDialog();
	
	CRect rc;

	GetClientRect (rc);

	m_List.InsertColumn (0, _T("Folder"), LVCFMT_LEFT, rc.Width ()/2 );
	m_List.InsertColumn (1, _T("Size"), LVCFMT_LEFT, rc.Width () /3 );
	m_List.InsertColumn (2, _T("%"), LVCFMT_LEFT, rc.Width () /6 );
	m_List.SetExtendedStyle (LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_SUBITEMIMAGES | LVS_EX_DOUBLEBUFFER);
	
	m_List.SetImageList (GetSysImageList (), LVSIL_SMALL  );

	dirs.GetDirInfoArrray (m_Array);
	
	std::sort (m_Array.begin(), m_Array.end(), sort_by_folder_size);

	LVITEM item;
	CString tmpString;

	size_t i = 0 ;
	int listIndex = 0;
	while (i < m_Array.size() && listIndex < 50)
	{
		
		if (IsDirectory (m_Array[i].folder))
		{
			item.mask = LVIF_TEXT | LVIF_IMAGE;
			item.iItem = i;
			item.iSubItem = 0;	
			item.iImage = CFileShellAttributes::GetFileIcon (m_Array[i].folder);
			item.pszText = (LPTSTR)(LPCTSTR)m_Array[i].folder;
			m_List.InsertItem (&item);

			tmpString = size_to_string (m_Array[i].dirinfo.m_Size);
			
			m_List.SetItem (listIndex, 1, LVIF_TEXT ,tmpString, 0, 0,0,0);
			listIndex++;
		}
		i++;		
	}

	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}
Esempio n. 5
0
void
BackupView::RefreshTotal()
{
	char sizeText[512];
	off_t totalSize = 0;

	for (uint32 i = 0; i < LOCATION_COUNT; i++) {
		BackupListItem* item = (BackupListItem*)fBackupList->ItemAt(i);
		if (item->Value() == B_CONTROL_ON) {
			totalSize += item->Bytes();
		}
	}
	
	// Update total backup size
	size_to_string(totalSize, sizeText, 512);
	fBackupSizeText->SetText(sizeText);
}
void
StatusView::ShowInfo(const FileInfo* info)
{
	if (info == fCurrentFileInfo)
		return;

	fCurrentFileInfo = info;

	if (info == NULL) {
		fPathView->SetText(kEmptyStr);
		fSizeView->SetText(kEmptyStr);
		fCountView->SetText(kEmptyStr);
		return;
	}

	if (!info->pseudo) {
		BNode node(&info->ref);
		if (node.InitCheck() != B_OK) {
			fPathView->SetText(B_TRANSLATE("file unavailable"));
			fSizeView->SetText(kEmptyStr);
			fCountView->SetText(kEmptyStr);
			return;
		}
	}

	float viewWidth = fPathView->Bounds().Width();
	string path;
	info->GetPath(path);
	BString pathLabel = path.c_str();
	be_plain_font->TruncateString(&pathLabel, B_TRUNCATE_BEGINNING, viewWidth);
	fPathView->SetText(pathLabel.String());

	char label[B_PATH_NAME_LENGTH];
	size_to_string(info->size, label, sizeof(label));
	fSizeView->SetText(label);

	if (info->count > 0) {
		char label[256];
		snprintf(label, sizeof(label), (info->count == 1) ?
			B_TRANSLATE("%d file") : B_TRANSLATE("%d files"), info->count);
		fCountView->SetText(label);
	} else {
		fCountView->SetText(kEmptyStr);
	}
}
Esempio n. 7
0
static int print_pkg(alpm_pkg_t *pkg, const char *format) {
  const char *f, *end;
  char fmt[64], buf[64];
  int len, out = 0;

  end = format + strlen(format);

  for (f = format; f < end; f++) {
    len = 0;
    if (*f == '%') {
      len = strspn(f + 1 + len, printf_flags);
      len += strspn(f + 1 + len, digits);
      snprintf(fmt, len + 3, "%ss", f);
      fmt[len + 1] = 's';
      f += len + 1;
      switch (*f) {
        /* simple attributes */
        case 'f': /* filename */
          out += printf(fmt, alpm_pkg_get_filename(pkg));
          break;
        case 'n': /* package name */
          out += printf(fmt, alpm_pkg_get_name(pkg));
          break;
        case 'v': /* version */
          out += printf(fmt, alpm_pkg_get_version(pkg));
          break;
        case 'd': /* description */
          out += printf(fmt, alpm_pkg_get_desc(pkg));
          break;
        case 'u': /* project url */
          out += printf(fmt, alpm_pkg_get_url(pkg));
          break;
        case 'p': /* packager name */
          out += printf(fmt, alpm_pkg_get_packager(pkg));
          break;
        case 's': /* md5sum */
          out += printf(fmt, alpm_pkg_get_md5sum(pkg));
          break;
        case 'a': /* architecutre */
          out += printf(fmt, alpm_pkg_get_arch(pkg));
          break;
        case 'i': /* has install scriptlet? */
          out += printf(fmt, alpm_pkg_has_scriptlet(pkg) ? "yes" : "no");
          break;
        case 'r': /* repo */
          out += printf(fmt, alpm_db_get_name(alpm_pkg_get_db(pkg)));
          break;
        case 'w': /* install reason */
          out += printf(fmt, alpm_pkg_get_reason(pkg) ? "dependency" : "explicit");
          break;
        case '!': /* result number */
          snprintf(buf, sizeof(buf), "%d", opt_pkgcounter++);
          out += printf(fmt, buf);
          break;
        case 'g': /* base64 gpg sig */
          out += printf(fmt, alpm_pkg_get_base64_sig(pkg));
          break;
        case 'h': /* sha256sum */
          out += printf(fmt, alpm_pkg_get_sha256sum(pkg));
          break;

        /* times */
        case 'b': /* build date */
          out += print_time(alpm_pkg_get_builddate(pkg));
          break;
        case 'l': /* install date */
          out += print_time(alpm_pkg_get_installdate(pkg));
          break;

        /* sizes */
        case 'k': /* download size */
          out += printf(fmt, size_to_string(alpm_pkg_get_size(pkg)));
          break;
        case 'm': /* install size */
          out += printf(fmt, size_to_string(alpm_pkg_get_isize(pkg)));
          break;

        /* lists */
        case 'F': /* files */
          out += print_filelist(alpm_pkg_get_files(pkg));
          break;
        case 'N': /* requiredby */
          out += print_list(alpm_pkg_compute_requiredby(pkg), NULL);
          break;
        case 'L': /* licenses */
          out += print_list(alpm_pkg_get_licenses(pkg), NULL);
          break;
        case 'G': /* groups */
          out += print_list(alpm_pkg_get_groups(pkg), NULL);
          break;
        case 'E': /* depends (shortdeps) */
          out += print_list(alpm_pkg_get_depends(pkg), (extractfn)alpm_dep_get_name);
          break;
        case 'D': /* depends */
          out += print_list(alpm_pkg_get_depends(pkg), (extractfn)alpm_dep_compute_string);
          break;
        case 'O': /* optdepends */
          out += print_list(alpm_pkg_get_optdepends(pkg), (extractfn)format_optdep);
          break;
        case 'o': /* optdepends (shortdeps) */
          out += print_list(alpm_pkg_get_optdepends(pkg), (extractfn)alpm_dep_get_name);
          break;
        case 'C': /* conflicts */
          out += print_list(alpm_pkg_get_conflicts(pkg), (extractfn)alpm_dep_get_name);
          break;
        case 'S': /* provides (shortdeps) */
          out += print_list(alpm_pkg_get_provides(pkg), (extractfn)alpm_dep_get_name);
          break;
        case 'P': /* provides */
          out += print_list(alpm_pkg_get_provides(pkg), (extractfn)alpm_dep_compute_string);
          break;
        case 'R': /* replaces */
          out += print_list(alpm_pkg_get_replaces(pkg), (extractfn)alpm_dep_get_name);
          break;
        case 'B': /* backup */
          out += print_list(alpm_pkg_get_backup(pkg), alpm_backup_get_name);
          break;
        case 'V': /* package validation */
          out += print_allocated_list(get_validation_method(pkg), NULL);
          break;
        case 'M': /* modified */
          out += print_allocated_list(get_modified_files(pkg), NULL);
          break;
        case '%':
          fputc('%', stdout);
          out++;
          break;
        default:
          fputc('?', stdout);
          out++;
          break;
      }
    } else if (*f == '\\') {
      char esc[3] = { f[0], f[1], '\0' };
      out += print_escaped(esc);
      ++f;
    } else {
      fputc(*f, stdout);
      out++;
    }
  }

  /* only print a delimeter if any package data was outputted */
  if (out > 0) {
    print_escaped(opt_delim);
  }

  return !out;
}
Esempio n. 8
0
static Menu*
add_save_debug_syslog_menu()
{
	Menu* menu = new(nothrow) Menu(STANDARD_MENU, "Save syslog to volume ...");
	MenuItem* item;

	const char* const kHelpText = "Currently only FAT32 volumes are supported. "
		"Newly plugged in removable devices are only recognized after "
		"rebooting.";

	int32 itemsAdded = 0;

	void* cookie;
	if (gRoot->Open(&cookie, O_RDONLY) == B_OK) {
		Node* node;
		while (gRoot->GetNextNode(cookie, &node) == B_OK) {
			Directory* volume = static_cast<Directory*>(node);
			Partition* partition;
			if (gRoot->GetPartitionFor(volume, &partition) != B_OK)
				continue;

			// we support only FAT32 volumes ATM
			if (partition->content_type == NULL
				|| strcmp(partition->content_type, kPartitionTypeFAT32) != 0) {
				continue;
			}

			char name[B_FILE_NAME_LENGTH];
			if (volume->GetName(name, sizeof(name)) != B_OK)
				strcpy(name, "unnamed");

			// append offset, size, and type to the name
			size_t len = strlen(name);
			char offsetBuffer[32];
			char sizeBuffer[32];
			snprintf(name + len, sizeof(name) - len,
				" (%s, offset %s, size %s)", partition->content_type,
				size_to_string(partition->offset, offsetBuffer,
					sizeof(offsetBuffer)),
				size_to_string(partition->size, sizeBuffer,
					sizeof(sizeBuffer)));

			item = new(nothrow) MenuItem(name);
			item->SetData(volume);
			item->SetTarget(&debug_menu_save_syslog);
			item->SetType(MENU_ITEM_NO_CHOICE);
			item->SetHelpText(kHelpText);
			menu->AddItem(item);
			itemsAdded++;
		}

		gRoot->Close(cookie);
	}

	if (itemsAdded == 0) {
		menu->AddItem(item
			= new(nothrow) MenuItem("No supported volumes found"));
		item->SetType(MENU_ITEM_NO_CHOICE);
		item->SetHelpText(kHelpText);
		item->SetEnabled(false);
	}

	menu->AddSeparatorItem();
	menu->AddItem(item = new(nothrow) MenuItem("Return to debug menu"));
	item->SetHelpText(kHelpText);

	return menu;
}
Esempio n. 9
0
void
BackupListItem::DrawItem(BView* owner, BRect /*bounds*/, bool complete)
{
	BListView* list = dynamic_cast<BListView*>(owner);

	if (list == NULL)
		return;

	owner->PushState();

	BRect bounds = list->ItemFrame(list->IndexOf(this));

	rgb_color textColor = ui_color(B_LIST_ITEM_TEXT_COLOR);
	rgb_color backgroundColor = ui_color(B_LIST_BACKGROUND_COLOR);

	if (fIndex % 2)
		backgroundColor = (rgb_color){ 247, 247, 247, 255 };

	// draw background
	list->SetDrawingMode(B_OP_OVER);
	list->SetHighColor(backgroundColor);
	list->FillRect(bounds);

	// set proper colors for "normal" items
	list->SetHighColor(textColor);
	list->SetLowColor(backgroundColor);

	// Set up points for things in BListItem
	BPoint checkboxPt = bounds.LeftTop();
	BPoint namePt = bounds.LeftTop();
	BPoint descriptionPt = bounds.LeftTop();
	BPoint sizePt = bounds.RightTop();
	namePt += BPoint(16 + 8, fFirstlineOffset);
	sizePt += BPoint(0, fFirstlineOffset);
	descriptionPt += BPoint(16 + 8, fSecondlineOffset);
	checkboxPt += BPoint(4, 2);

	list->SetFont(be_bold_font);
	list->DrawString(fName.String(), namePt);

	char sizeText[512];
	size_to_string(fSize, sizeText, 512);
	BString sizeString(sizeText);

	list->SetFont(be_plain_font);
	sizePt -= BPoint(
		be_plain_font->StringWidth(sizeString.String()) + 4.0f, 0);

	list->DrawString(sizeString.String(), sizePt);

	if (textColor.red + textColor.green + textColor.blue > 128 * 3)
		list->SetHighColor(tint_color(textColor, B_DARKEN_1_TINT));
	else
		list->SetHighColor(tint_color(textColor, B_LIGHTEN_1_TINT));

	list->SetFontSize(11);
	list->SetHighColor(ui_color(B_LIST_SELECTED_ITEM_TEXT_COLOR));
	list->DrawString(fDescription.String(), descriptionPt);

	if (!fEnabled) {
		fEnabled = new BCheckBox(BRect(0, 0, 16, 16), fName.String(),
			fName.String(), new BMessage(kMsgUpdateSelection));
		list->AddChild(fEnabled);
		// First run, set default value
		fEnabled->SetValue(gLocationMap[fIndex].defaultValue
			? B_CONTROL_ON : B_CONTROL_OFF);
	}

	fEnabled->SetHighColor(textColor);
	fEnabled->SetLowColor(backgroundColor);
	fEnabled->MoveTo(checkboxPt.x, checkboxPt.y);

	owner->PopState();
}
Esempio n. 10
0
static bool format_setup(void)
{
  struct device **devices = 0;
  struct device **p = 0;
  int n = 0;
  int size = 128;
  int i = 0;
  int j = 0;

  if((devices = device_probe_all(true)) == 0)
    return false;

  targets = malloc0(size * sizeof(struct format *));

  for( p = devices ; *p != 0 ; ++p )
  {
    struct device *device = *p;
    struct disk *disk = disk_open(device);
    struct format *target = 0;
    char buf[PATH_MAX] = {0};
 
    if(disk == 0)
    {
      target = malloc0(sizeof(struct format));
    
      add_target(target,&n,&size);
    
      target->devicepath = strdup(device_get_path(device));
      
      size_to_string(buf,PATH_MAX,device_get_size(device),true);
    
      target->size = strdup(buf);
    
      probe_filesystem(target);
    }
    else
    {
      for( i = 0, j = disk_partition_get_count(disk) ; i < j ; ++i )
      {
        const char *purpose = disk_partition_get_purpose(disk,i);
      
        if(
          strcmp(purpose,"data") != 0 && 
          strcmp(purpose,"swap") != 0 && 
          strcmp(purpose,"efi")  != 0
        )
          continue;
        
        target = malloc0(sizeof(struct format));
      
        add_target(target,&n,&size);
      
        snprintf(buf,PATH_MAX,"%s%d",device_get_path(device),disk_partition_get_number(disk,i));
        
        target->devicepath = strdup(buf);
        
        size_to_string(buf,PATH_MAX,disk_partition_get_size(disk,i),true);
        
        target->size = strdup(buf);
        
        probe_filesystem(target);
      }
    }
    
    device_close(device);
  }

  free(devices);

  targets = realloc(targets,(n + 1) * sizeof(struct format *));

  return true;
}
Esempio n. 11
0
float
PieView::_DrawDirectory(BRect b, FileInfo* info, float parentSpan,
	float beginAngle, int colorIdx, int level)
{
	if (b.Width() < 2.0 * (kPieCenterSize + level * kPieRingSize
		+ kPieOuterMargin + kPieInnerMargin)) {
		return 0.0;
	}

	if (info != NULL && info->color >= 0 && level == 0)
		colorIdx = info->color % kBasePieColorCount;
	else if (info != NULL)
		info->color = colorIdx;

	VolumeSnapshot* snapshot = fScanner->Snapshot();

	float cx = floorf(b.left + b.Width() / 2.0 + 0.5);
	float cy = floorf(b.top + b.Height() / 2.0 + 0.5);

	float mySpan;

	if (level == 0) {
		// Make room for mouse over info.
		fMouseOverInfo.clear();
		fMouseOverInfo[0] = SegmentList();

		// Draw the center circle.
		const char* displayName;
		if (info == NULL) {
			// NULL represents the entire volume.  Show used and free space in
			// the center circle, with the used segment representing the
			// volume's root directory.
			off_t volCapacity = snapshot->capacity;
			mySpan = 360.0 * (volCapacity - snapshot->freeBytes) / volCapacity;

			SetHighColor(kEmptySpcColor);
			FillEllipse(BPoint(cx, cy), kPieCenterSize, kPieCenterSize);

			SetHighColor(kBasePieColor[0]);
			FillArc(BPoint(cx, cy), kPieCenterSize, kPieCenterSize, 0.0,
				mySpan);

			// Show total volume capacity.
			char label[B_PATH_NAME_LENGTH];
			size_to_string(volCapacity, label, sizeof(label));
			SetHighColor(kPieBGColor);
			SetDrawingMode(B_OP_OVER);
			DrawString(label, BPoint(cx - StringWidth(label) / 2.0,
				cy + fFontHeight + kSmallVMargin));
			SetDrawingMode(B_OP_COPY);

			displayName = snapshot->name.c_str();

			// Record in-use space and free space for use during MouseMoved().
			info = snapshot->rootDir;
			info->color = colorIdx;
			fMouseOverInfo[0].push_back(Segment(0.0, mySpan, info));
			if (mySpan < 360.0 - kMinSegmentSpan) {
				fMouseOverInfo[0].push_back(Segment(mySpan, 360.0,
					snapshot->freeSpace));
			}
		} else {
			// Show a normal directory.
			SetHighColor(kBasePieColor[colorIdx]);
			FillEllipse(BRect(cx - kPieCenterSize, cy - kPieCenterSize,
				cx + kPieCenterSize + 0.5, cy + kPieCenterSize + 0.5));
			displayName = info->ref.name;
			mySpan = 360.0;

			// Record the segment for use during MouseMoved().
			fMouseOverInfo[0].push_back(Segment(0.0, mySpan, info));
		}

		SetPenSize(1.0);
		SetHighColor(kOutlineColor);
		StrokeEllipse(BPoint(cx, cy), kPieCenterSize + 0.5,
			kPieCenterSize + 0.5);

		// Show the name of the volume or directory.
		BString label(displayName);
		BFont font;
		GetFont(&font);
		font.TruncateString(&label, B_TRUNCATE_END,
			2.0 * (kPieCenterSize - kSmallHMargin));
		float labelWidth = font.StringWidth(label.String());

		SetHighColor(kPieBGColor);
		SetDrawingMode(B_OP_OVER);
		DrawString(label.String(), BPoint(cx - labelWidth / 2.0, cy));
		SetDrawingMode(B_OP_COPY);
		beginAngle = 0.0;
	} else {
		// Draw an exterior segment.
		float parentSize;
		if (info->parent == NULL)
			parentSize = (float)snapshot->capacity;
		else
			parentSize = (float)info->parent->size;

		mySpan = parentSpan * (float)info->size / parentSize;
		if (mySpan >= kMinSegmentSpan) {
			const float tint = 1.4f - level * 0.08f;
			float radius = kPieCenterSize + level * kPieRingSize
				- kPieRingSize / 2.0;

			// Draw the grey border
			SetHighColor(tint_color(kOutlineColor, tint));
			SetPenSize(kPieRingSize + 1.5f);
			StrokeArc(BPoint(cx, cy), radius, radius,
				beginAngle - 0.001f * radius, mySpan  + 0.002f * radius);

			// Draw the colored area
			rgb_color color = tint_color(kBasePieColor[colorIdx], tint);
			SetHighColor(color);
			SetPenSize(kPieRingSize);
			StrokeArc(BPoint(cx, cy), radius, radius, beginAngle, mySpan);

			// Record the segment for use during MouseMoved().
			if (fMouseOverInfo.find(level) == fMouseOverInfo.end())
				fMouseOverInfo[level] = SegmentList();

			fMouseOverInfo[level].push_back(
				Segment(beginAngle, beginAngle + mySpan, info));
		}
	}

	// Draw children.
	vector<FileInfo*>::iterator i = info->children.begin();
	while (i != info->children.end()) {
		float childSpan
			= _DrawDirectory(b, *i, mySpan, beginAngle, colorIdx, level + 1);
		if (childSpan >= kMinSegmentSpan) {
			beginAngle += childSpan;
			colorIdx = (colorIdx + 1) % kBasePieColorCount;
		}
		i++;
	}

	return mySpan;
}