예제 #1
0
int GUIAction::mountsystemtoggle(std::string arg)
{
	int op_status = 0;
	bool remount_system = PartitionManager.Is_Mounted_By_Path("/system");

	operation_start("Toggle System Mount");
	if (!PartitionManager.UnMount_By_Path("/system", true)) {
		op_status = 1; // fail
	} else {
		TWPartition* Part = PartitionManager.Find_Partition_By_Path("/system");
		if (Part) {
			if (arg == "0") {
				DataManager::SetValue("tw_mount_system_ro", 0);
				Part->Change_Mount_Read_Only(false);
			} else {
				DataManager::SetValue("tw_mount_system_ro", 1);
				Part->Change_Mount_Read_Only(true);
			}
			if (remount_system) {
				Part->Mount(true);
			}
			op_status = 0; // success
		} else {
			op_status = 1; // fail
		}
	}

	operation_end(op_status);
	return 0;
}
예제 #2
0
int GUIPartitionList::NotifyTouch(TOUCH_STATE state, int x, int y)
{
	if(!isConditionTrue())
		return -1;

	static int lastY = 0, last2Y = 0;
	int selection = 0;

	switch (state)
	{
	case TOUCH_START:
		if (scrollingSpeed != 0)
			startSelection = -1;
		else
			startSelection = GetSelection(x,y);
		isHighlighted = (startSelection > -1);
		if (isHighlighted)
			mUpdate = 1;
		startY = lastY = last2Y = y;
		scrollingSpeed = 0;
		break;

	case TOUCH_DRAG:
		// Check if we dragged out of the selection window
		if (GetSelection(x, y) == -1) {
			last2Y = lastY = 0;
			if (isHighlighted) {
				isHighlighted = false;
				mUpdate = 1;
			}
			break;
		}

		// Fast scroll
		if(mFastScrollRectX != -1 && x >= mRenderX + mRenderW - mFastScrollW)
		{
			int pct = ((y-mRenderY-mHeaderH)*100)/(mRenderH-mHeaderH);
			int totalSize = mList.size();
			int lines = (mRenderH - mHeaderH) / (actualLineHeight);

			float l = float((totalSize-lines)*pct)/100;
			if(l + lines >= totalSize)
			{
				mStart = totalSize - lines;
				scrollingY = 0;
			}
			else
			{
				mStart = l;
				scrollingY = -(l - int(l))*actualLineHeight;
			}

			startSelection = -1;
			mUpdate = 1;
			scrollingSpeed = 0;
			isHighlighted = false;
			break;
		}

		// Provide some debounce on initial touches
		if (startSelection != -1 && abs(y - startY) < touchDebounce) {
			isHighlighted = true;
			mUpdate = 1;
			break;
		}

		isHighlighted = false;
		last2Y = lastY;
		lastY = y;	
		startSelection = -1;

		// Handle scrolling
		scrollingY += y - startY;
		startY = y;
		while(mStart && scrollingY > 0) {
			mStart--;
			scrollingY -= actualLineHeight;
		}
		if (mStart == 0 && scrollingY > 0)
			scrollingY = 0;
		{
			int totalSize = mList.size();
			int lines = (mRenderH - mHeaderH) / (actualLineHeight);

			if (totalSize > lines) {
				int bottom_offset = ((int)(mRenderH) - mHeaderH) - (lines * actualLineHeight);

				bottom_offset -= actualLineHeight;

				while (mStart + lines + (bottom_offset ? 1 : 0) < totalSize && abs(scrollingY) > actualLineHeight) {
					mStart++;
					scrollingY += actualLineHeight;
				}
				if (bottom_offset != 0 && mStart + lines + 1 >= totalSize && scrollingY <= bottom_offset) {
					mStart = totalSize - lines - 1;
					scrollingY = bottom_offset;
				} else if (mStart + lines >= totalSize && scrollingY < 0) {
					mStart = totalSize - lines;
					scrollingY = 0;
				}
			} else
				scrollingY = 0;
		}
		mUpdate = 1;
		break;

	case TOUCH_RELEASE:
		isHighlighted = false;
		if (startSelection >= 0)
		{
			// We've selected an item!
			int listSize = mList.size();
			int selectY = scrollingY, actualSelection = mStart;

			// Move the selection to the proper place in the array
			while (selectY + actualLineHeight < startSelection) {
				selectY += actualLineHeight;
				actualSelection++;
			}

			if (actualSelection < listSize && ListType == "mount") {
				DataManager::Vibrate("tw_button_vibrate");

				if (!mList.at(actualSelection).selected) {
					if (PartitionManager.Mount_By_Path(mList.at(actualSelection).Mount_Point, true)) {
						mList.at(actualSelection).selected = 1;
						mUpdate = 1;
					}
				} else {
					if (PartitionManager.UnMount_By_Path(mList.at(actualSelection).Mount_Point, true)) {
						mList.at(actualSelection).selected = 0;
						mUpdate = 1;
					}
				}
			} else if (actualSelection < listSize && !mVariable.empty()) {
				DataManager::Vibrate("tw_button_vibrate");

				if (ListType == "storage") {
					int i;
					std::string str = mList.at(actualSelection).Mount_Point;
					bool update_size = false;
					TWPartition* Part = PartitionManager.Find_Partition_By_Path(str);
					if (Part == NULL) {
						LOGERR("Unable to locate partition for '%s'\n", str.c_str());
						return 0;
					}
					if (!Part->Is_Mounted() && Part->Removable)
						update_size = true;
					if (!Part->Mount(true)) {
						// Do Nothing
					} else if (update_size && !Part->Update_Size(true)) {
						// Do Nothing
					} else {
						for (i=0; i<listSize; i++)
							mList.at(i).selected = 0;

						if (update_size) {
							char free_space[255];
							sprintf(free_space, "%llu", Part->Free / 1024 / 1024);
							mList.at(actualSelection).Display_Name = Part->Storage_Name + " (";
							mList.at(actualSelection).Display_Name += free_space;
							mList.at(actualSelection).Display_Name += "MB)";
						}
						mList.at(actualSelection).selected = 1;
						mUpdate = 1;
						
						DataManager::SetValue(mVariable, str);
					}
				} else {
					if (mList.at(actualSelection).selected)
						mList.at(actualSelection).selected = 0;
					else
						mList.at(actualSelection).selected = 1;

					int i;
					string variablelist;
					for (i=0; i<listSize; i++) {
						if (mList.at(i).selected) {
							variablelist += mList.at(i).Mount_Point + ";";
						}
					}

					mUpdate = 1;
					if (selectedList.empty())
						DataManager::SetValue(mVariable, variablelist);
					else
						DataManager::SetValue(selectedList, variablelist);
				}
			}
		} else {
			// This is for kinetic scrolling
			scrollingSpeed = lastY - last2Y;
			if (abs(scrollingSpeed) > SCROLLING_FLOOR)
				scrollingSpeed *= SCROLLING_MULTIPLIER;
			else
				scrollingSpeed = 0;
		}
	case TOUCH_REPEAT:
	case TOUCH_HOLD:
		break;
	}
	return 0;
}