Esempio n. 1
0
// Free list of backdrop objects
void backdrop_free_list(BackdropInfo *info)
{
	BackdropObject *object;

	// Invalid info?
	if (!info) return;

	// Lock backdrop list
	lock_listlock(&info->objects,1);

	// Go through backdrop list
	for (object=(BackdropObject *)info->objects.list.lh_Head;
		object->node.ln_Succ;)
	{
		BackdropObject *next=(BackdropObject *)object->node.ln_Succ;

		// Remove object
		backdrop_remove_object(info,object);

		// Get next object
		object=next;
	}

	// Unlock backdrop list
	unlock_listlock(&info->objects);
}
// Got a notify message from PutDiskObject()
BOOL backdrop_check_notify(
	BackdropInfo *info,
	DOpusNotify *notify,
	Lister *lister)
{
	char *name_buf;
	BOOL disk=0,ret=0;
	struct List *search;
	BackdropObject *object;

	if (!(name_buf=AllocVec(256,0)))
		return 0;

	// Disk icon?
	if (notify->dn_Name[strlen(notify->dn_Name)-1]==':')
	{
		char *ptr;

		// Get volume name
		if ((ptr=strchr(notify->dn_Name,':')))
		{
			stccpy(name_buf,notify->dn_Name,ptr-notify->dn_Name+1);
			disk=1;
		}
	}

	// Otherwise copy name and clear it
	else
	{
		// Get name pointer
		char *name=FilePart(notify->dn_Name);

		// Copy name
		strcpy(name_buf,name);
		*name=0;

		// Strip trailing '/'
		if (*(name-1)=='/') *(name-1)=0;
	}

	// Is this a lister?
	if (lister)
	{
		short len;
		BOOL ok=0;

		// Match length
		len=strlen(notify->dn_Name);

		// See if strings match
		if (strnicmp(lister->cur_buffer->buf_Path,notify->dn_Name,len)==0)
		{
			// Check termination
			if (lister->cur_buffer->buf_Path[len]=='\0') ok=1;

			// / can terminate too
			else
			if (lister->cur_buffer->buf_Path[len]=='/' &&
				lister->cur_buffer->buf_Path[len+1]=='\0') ok=1;
		}

		// Didn't match?
		if (!ok)
		{
			// Free message
			ReplyFreeMsg(notify);	
			FreeVec(name_buf);
			return 0;
		}
	}

	// Lock backdrop list
	lock_listlock(&info->objects,1);

	// See if there's an icon of this name
	search=&info->objects.list;
	while ((object=(BackdropObject *)FindNameI(search,name_buf)))
	{
		// Disk?
		if (object->type==BDO_DISK && disk)
		{
			// Matched
			break;
		}

		// Valid object?
		else
		if (object->type!=BDO_APP_ICON &&
			object->type!=BDO_BAD_DISK &&
			object->path)
		{
			char *path=0;
			BPTR lock;

			// If no lister, get full path of object
			if (!lister && (path=AllocVec(512,0)))
			{
				// Lock path
				if ((lock=Lock(object->path,ACCESS_READ)))
				{
					// Get full path
					DevNameFromLockDopus(lock,path,512);
					UnLock(lock);
				}

				// Failed
				else strcpy(path,object->path);
			}
					
			// Objects in same directory?
			if (lister || stricmp(notify->dn_Name,(path)?path:object->path)==0)
			{
				// Free path
				if (path) FreeVec(path);

				// Matched
				break;
			}

			// Free path
			if (path) FreeVec(path);
		}

		// If this is a lister, there could only be one
		if (lister)
		{
			object=0;
			break;
		}

		// Keep searching from this object
		search=(struct List *)object;
	}

	// Got object?
	if (object)
	{
		ULONG old_image1=0,old_image2=0,new_image1,new_image2,old_flags=0,new_flags;
		BOOL redraw=0;
		struct DiskObject *old;

		// Save old icon
		old=object->icon;
		object->icon=0;

		// Not deleted?
		if (!notify->dn_Flags)
		{
			// Get image checksums
			old_image1=IconCheckSum(old,0);
			old_image2=IconCheckSum(old,1);
			old_flags=GetIconFlags(old);

			// Get new icon
			backdrop_get_icon(info,object,GETICON_CD|GETICON_NO_POS|GETICON_FAIL);
		}

		// No icon now?
		if (!object->icon)
		{
			// Replace old icon
			object->icon=old;

			// Erase old object
			backdrop_erase_icon(info,object,BDSF_RECALC);

			// Is object a disk?
			if (object->type==BDO_DISK)
			{
				// Signal to refresh drives
				IPC_Command(info->ipc,MAINCMD_REFRESH_DRIVES,0,0,0,0);
			}

			// Remove object from list
			backdrop_remove_object(info,object);
		}

		// Ok to keep going
		else
		{
			// Get image checksums
			new_image1=IconCheckSum(object->icon,0);
			new_image2=IconCheckSum(object->icon,1);
			new_flags=GetIconFlags(object->icon);

			// Mask out uninteresting flag bits
			old_flags&=ICONF_BORDER_OFF|ICONF_BORDER_ON|ICONF_NO_LABEL;
			new_flags&=ICONF_BORDER_OFF|ICONF_BORDER_ON|ICONF_NO_LABEL;

			// Need to redraw?
			if (old_image1!=new_image1 ||
				old_image2!=new_image2 ||
				old_flags!=new_flags)
			{
				// Erase old object
				backdrop_erase_icon(info,object,0);
				redraw=1;
			}

			// Free old icon
			if (old)
			{
				// Free icon remapping
				RemapIcon(old,(info->window)?info->window->WScreen:0,1);

				// Free icon
				FreeCachedDiskObject(old);
			}

			// Fix new icon size
			backdrop_get_icon(info,object,GETICON_POS_ONLY|GETICON_SAVE_POS|GETICON_KEEP);

			// Need to get masks?
			if (!backdrop_icon_border(object))
			{
				// Get masks for this icon
				backdrop_get_masks(object);
			}
			
			// Show new icon
			if (redraw) backdrop_render_object(info,object,BRENDERF_CLIP);
		}

		ret=1;
	}

	// Otherwise, got lister?
	else
	if (lister)
	{
		// Tell lister to get icons
		IPC_Command(lister->ipc,LISTER_GET_ICONS,0,0,0,0);
		ret=1;
	}

	// Or, on the desktop?
	else
	if (info->flags&BDIF_MAIN_DESKTOP)
	{
		BPTR lock1,lock2;

		// Lock the desktop folder and the changed directory
		if ((lock1=Lock(environment->env->desktop_location,ACCESS_READ)) &&
			(lock2=Lock(notify->dn_Name,ACCESS_READ)))
		{
			// Same directory?
			if (SameLock(lock1,lock2)==LOCK_SAME)
			{
				// Update the desktop folder
				misc_startup("dopus_desktop_update",MENU_UPDATE_DESKTOP,GUI->window,0,TRUE);
			}

			// Unlock second lock
			UnLock(lock2);
		}

		// Unlock first lock
		UnLock(lock1);
	}

	// Unlock list
	unlock_listlock(&info->objects);

	// Free message
	ReplyFreeMsg(notify);	
	FreeVec(name_buf);
	return ret;
}
Esempio n. 3
0
void desktop_delete(IPCData *ipc,BackdropInfo *info,BackdropObject *only_one)
{
	short groupcount=0,filecount=0,assigncount=0,othercount=0,dircount=0;
	BackdropObject *object=0;
	Att_List *list;
	Att_Node *node;
	char buf[100];

	// Create list
	if (!(list=Att_NewList(LISTF_POOL)))
		return;

	// Lock backdrop list
	lock_listlock(&info->objects,0);

	// Go through backdrop list
	while ((object=backdrop_next_object(info,object,only_one)))
	{
		// Group?
		if (object->type==BDO_GROUP) ++groupcount;

		// Assign?
		else
		if (object->flags&BDOF_ASSIGN) ++assigncount;

		// Group object?
		else
		if (object->type==BDO_LEFT_OUT && info->flags&BDIF_GROUP) ++filecount;

		// Desktop object?
		else
		if (object->type==BDO_LEFT_OUT && object->flags&BDOF_DESKTOP_FOLDER)
		{
			++othercount;
			if (object->icon->do_Type==WBDRAWER) ++dircount;
		}

		// Something else
		else continue;

		// Add to list
		Att_NewNode(list,0,(ULONG)object,0);
	}

	// Unlock backdrop list
	unlock_listlock(&info->objects);

	// Nothing to delete?
	if (IsListEmpty((struct List *)list))
	{
		Att_RemList(list,0);
		return;
	}

	// Build message; start with query
	strcpy(info->buffer,GetString(&locale,MSG_DESKTOP_REALLY_DELETE));

	// Any groups?
	if (groupcount>0)
	{
		lsprintf(buf,GetString(&locale,MSG_DESKTOP_DELETE_GROUPS),groupcount);
		strcat(info->buffer,buf);
	}

	// Or assigns?
	else
	if (assigncount>0)
	{
		lsprintf(buf,GetString(&locale,MSG_DESKTOP_DELETE_ASSIGNS),assigncount);
		strcat(info->buffer,buf);
	}

	// Any group files?
	else
	if (filecount>0)
	{
		// Add file count
		lsprintf(buf,GetString(&locale,MSG_DESKTOP_DELETE_GROUP_OBJECTS),filecount);
		strcat(info->buffer,buf);
	}

	// Desktop objects?
	if (othercount>0)
	{
		BOOL cr=0;

		// Add CR?
		if (groupcount>0 || assigncount>0 || filecount>0) cr=1;

		// Add files
		if (othercount>dircount)
		{
			lsprintf(buf,GetString(&locale,MSG_DESKTOP_DELETE_DESKTOP_FILES),othercount-dircount);
			if (cr) strcat(info->buffer,"\n");
			strcat(info->buffer,buf);
			cr=1;
		}

		// Add dirs
		if (dircount>0)
		{
			lsprintf(buf,GetString(&locale,MSG_DESKTOP_DELETE_DESKTOP_DIRS),dircount);
			if (cr) strcat(info->buffer,"\n");
			strcat(info->buffer,buf);
		}
	}
			
	// Add question mark
	strcat(info->buffer,"?");

	// Display requester
	if (!(super_request_args(
		GUI->screen_pointer,
		info->buffer,
		SRF_IPC|SRF_SCREEN_PARENT,
		ipc,
		GetString(&locale,MSG_DELETE),
		GetString(&locale,MSG_CANCEL),0)))
	{
		Att_RemList(list,0);
		return;
	}

	// Check owner for refresh
	if (info->lister)
		IPC_Command(info->lister->ipc,LISTER_CHECK_REFRESH,0,0,0,REPLY_NO_PORT);

	// Group objects?
	if (info->flags&BDIF_GROUP)
	{
		// Send command to group
		IPC_Command(info->ipc,GROUP_DELETE,0,only_one,0,0);
	}

	// Otherwise
	else
	{
		// Go through the list
		for (node=(Att_Node *)list->list.lh_Head;
			node->node.ln_Succ;
			node=(Att_Node *)node->node.ln_Succ)
		{
			// Lock backdrop list
			lock_listlock(&info->objects,1);

			// Get object
			if ((object=find_backdrop_object(info,(BackdropObject *)node->data)))
			{
				// Group?
				if (object->type==BDO_GROUP)
				{
					// Delete this group
					backdrop_delete_group(info,object);
				}

				// Assign?
				else
				if (object->flags&BDOF_ASSIGN)
				{
					// Copy name, strip trailing colon
					strcpy(info->buffer+2,object->name);
					info->buffer[strlen(info->buffer+2)+1]=0;

					// Delete assign
					if (AssignLock(info->buffer+2,0))
					{
						// Erase object
						backdrop_erase_icon(info,object,0);

						// Remove object
						backdrop_remove_object(info,object);
					}
				}
			}

			// Unlock backdrop list
			unlock_listlock(&info->objects);
		}
	}

	// Free list
	Att_RemList(list,0);

	// Recalc backdrop objects
	backdrop_calc_virtual(info);

	// Delete other things?
	if (othercount>0)
	{
		// Run delete function
		icon_function(info,0,0,def_function_delete_quiet,0);
	}
}