Exemple #1
0
/* Copy the file src to dst 4KB per time */
static int copyFile(const char *src, const char *dst, const char *filename)
{
    FILE *in = fopen(src, "rb");
    FILE *out = openTarget(dst, filename);
    char buf[4096];
    int error = 0;

    if (in == NULL || out == NULL)
        return -1;

    while (!feof(in)) {
        if (fread(buf, 4096, 1, in) == -1) {
            if (ferror(in)) {
                clearerr(in);
                error = -1;
                break;
            }
        } else {
            fwrite(buf, 4096, 1, out);
            if (ferror(out)) {
                clearerr(out);
                error = -1;
                break;
            }
        }
    }
#ifndef WIN32
    fchmod(fileno(out), S_IRUSR | S_IWUSR | S_IXUSR);
#endif
    fclose(in);
    fclose(out);

    return error;
}
Exemple #2
0
/*
 * extract from the archive
 * and copy to the filesystem
 * relative to the directory the archive's in
 */
int extract2fs(ARCHIVE_STATUS *status, TOC *ptoc)
{
	FILE *out;
	unsigned char *data = extract(status, ptoc);

    if (createTempPath(status) == -1){
        return -1;
    }

	out = openTarget(status->temppath, ptoc->name);

	if (out == NULL)  {
		FATALERROR("%s could not be extracted!\n", ptoc->name);
		return -1;
	}
	else {
		fwrite(data, ntohl(ptoc->ulen), 1, out);
#ifndef WIN32
		fchmod(fileno(out), S_IRUSR | S_IWUSR | S_IXUSR);
#endif
		fclose(out);
	}
	free(data);
	return 0;
}
Exemple #3
0
/*
 * extract from the archive
 * and copy to the filesystem 
 * relative to the directory the archive's in
 */
int extract2fs(TOC *ptoc)
{
#ifdef WIN32
	char *p;
#endif
	FILE *out;
	unsigned char *data = extract(ptoc);

	if (!f_workpath) {
		getTempPath(f_temppath);
#ifdef WIN32
		strcpy(f_temppathraw, f_temppath);
		for ( p=f_temppath; *p; p++ )
			if (*p == '\\')
				*p = '/';
#endif
		f_workpath = f_temppath;
	}
	out = openTarget(f_workpath, ptoc->name);

	if (out == NULL)  {
		FATALERROR(ptoc->name);
		FATALERROR(" could not be extracted!\n");
	}
	else {
		fwrite(data, ntohl(ptoc->ulen), 1, out);
#ifndef WIN32
		fchmod(fileno(out), S_IRUSR | S_IWUSR | S_IXUSR);
#endif
		fclose(out);
	}
	free(data);
	return 0;
}
Exemple #4
0
void
MainWindow::MessageReceived(BMessage* message)
{
	switch (message->what) {
		case MSG_LAUNCH: 
		{
			BView* pointer;
			if (message->FindPointer("be:source", (void**)&pointer) < B_OK)
				break;
			LaunchButton* button = dynamic_cast<LaunchButton*>(pointer);
			if (button == NULL)
				break;
			BString errorMessage;
			bool launchedByRef = false;
			if (button->Ref()) {
				BEntry entry(button->Ref(), true);
				if (entry.IsDirectory()) {
					// open in Tracker
					BMessenger messenger("application/x-vnd.Be-TRAK");
					if (messenger.IsValid()) {
						BMessage trackerMessage(B_REFS_RECEIVED);
						trackerMessage.AddRef("refs", button->Ref());
						status_t ret = messenger.SendMessage(&trackerMessage);
						if (ret < B_OK) {
							errorMessage = B_TRANSLATE("Failed to send "
							"'open folder' command to Tracker.\n\nError: ");
							errorMessage << strerror(ret);
						} else
							launchedByRef = true;
					} else
						errorMessage = ("Failed to open folder - is Tracker "
							"running?");
				} else {
					status_t ret = be_roster->Launch(button->Ref());
					if (ret < B_OK && ret != B_ALREADY_RUNNING) {
						BString errStr(B_TRANSLATE("Failed to launch '%1'.\n"
							"\nError:"));
						BPath path(button->Ref());
						if (path.InitCheck() >= B_OK)
							errStr.ReplaceFirst("%1", path.Path());
						else
							errStr.ReplaceFirst("%1", button->Ref()->name);
						errorMessage << errStr.String() << " ";
						errorMessage << strerror(ret);
					} else
						launchedByRef = true;
				}
			}
			if (!launchedByRef && button->AppSignature()) {
				status_t ret = be_roster->Launch(button->AppSignature());
				if (ret != B_OK && ret != B_ALREADY_RUNNING) {
					BString errStr(B_TRANSLATE("\n\nFailed to launch application "
						"with signature '%2'.\n\nError:"));
					errStr.ReplaceFirst("%2", button->AppSignature());
					errorMessage << errStr.String() << " ";
					errorMessage << strerror(ret);
				} else {
					// clear error message on success (might have been
					// filled when trying to launch by ref)
					errorMessage = "";
				}
			} else if (!launchedByRef) {
				errorMessage = B_TRANSLATE("Failed to launch 'something', "
					"error in Pad data.");
			}
			if (errorMessage.Length() > 0) {
				BAlert* alert = new BAlert("error", errorMessage.String(),
					B_TRANSLATE("Bummer"), NULL, NULL, B_WIDTH_FROM_WIDEST);
				alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
				alert->Go(NULL);
			}
			break;
		}
		case MSG_ADD_SLOT: 
		{
			LaunchButton* button;
			if (message->FindPointer("be:source", (void**)&button) >= B_OK) {
				fPadView->AddButton(new LaunchButton("launch button",
					NULL, new BMessage(MSG_LAUNCH)), button);
			}
			break;
		}
		case MSG_CLEAR_SLOT: 
		{
			LaunchButton* button;
			if (message->FindPointer("be:source", (void**)&button) >= B_OK)
				button->SetTo((entry_ref*)NULL);
			break;
		}
		case MSG_REMOVE_SLOT: 
		{
			LaunchButton* button;
			if (message->FindPointer("be:source", (void**)&button) >= B_OK) {
				if (fPadView->RemoveButton(button))
					delete button;
			}
			break;
		}
		case MSG_SET_DESCRIPTION: 
		{
			LaunchButton* button;
			if (message->FindPointer("be:source", (void**)&button) >= B_OK) {
				const char* name;
				if (message->FindString("name", &name) >= B_OK) {
					// message comes from a previous name panel
					button->SetDescription(name);
					BRect namePanelFrame;
					if (message->FindRect("frame", &namePanelFrame) == B_OK) {
						((App*)be_app)->SetNamePanelSize(
							namePanelFrame.Size());
					}
				} else {
					// message comes from pad view
					entry_ref* ref = button->Ref();
					if (ref) {
						BString helper(B_TRANSLATE("Description for '%3'"));
						helper.ReplaceFirst("%3", ref->name);
						// Place the name panel besides the pad, but give it
						// the user configured size.
						BPoint origin = B_ORIGIN;
						BSize size = ((App*)be_app)->NamePanelSize();
						NamePanel* panel = new NamePanel(helper.String(),
							button->Description(), this, this,
							new BMessage(*message), size);
						panel->Layout(true);
						size = panel->Frame().Size();
						BScreen screen(this);
						BPoint mousePos;
						uint32 buttons;
						fPadView->GetMouse(&mousePos, &buttons, false);
						fPadView->ConvertToScreen(&mousePos);
						if (fPadView->Orientation() == B_HORIZONTAL) {
							// Place above or below the pad
							origin.x = mousePos.x - size.width / 2;
							if (screen.Frame().bottom - Frame().bottom
									> size.height + 20) {
								origin.y = Frame().bottom + 10;
							} else {
								origin.y = Frame().top - 10 - size.height;
							}
						} else {
							// Place left or right of the pad
							origin.y = mousePos.y - size.height / 2;
							if (screen.Frame().right - Frame().right
									> size.width + 20) {
								origin.x = Frame().right + 10;
							} else {
								origin.x = Frame().left - 10 - size.width;
							}
						}
						panel->MoveTo(origin);
						panel->Show();
					}
				}
			}
			break;
		}
		case MSG_ADD_WINDOW: 
		{
			BMessage settings('sett');
			SaveSettings(&settings);
			message->AddMessage("window", &settings);
			be_app->PostMessage(message);
			break;
		}
		case MSG_SHOW_BORDER:
			SetLook(B_TITLED_WINDOW_LOOK);
			break;
		case MSG_HIDE_BORDER:
			SetLook(B_BORDERED_WINDOW_LOOK);
			break;
		case MSG_TOGGLE_AUTORAISE:
			ToggleAutoRaise();
			break;
		case MSG_SHOW_ON_ALL_WORKSPACES:
			fShowOnAllWorkspaces = !fShowOnAllWorkspaces;
			if (fShowOnAllWorkspaces)
				SetWorkspaces(B_ALL_WORKSPACES);
			else
				SetWorkspaces(1L << current_workspace());
			break;
		case MSG_OPEN_CONTAINING_FOLDER: 
		{
			LaunchButton* button;
			if (message->FindPointer("be:source", (void**)&button) == B_OK && button->Ref() != NULL) {
				entry_ref target = *button->Ref();
				BEntry openTarget(&target);
				BMessage openMsg(B_REFS_RECEIVED);
				BMessenger tracker("application/x-vnd.Be-TRAK");
				openTarget.GetParent(&openTarget);
				openTarget.GetRef(&target);
				openMsg.AddRef("refs",&target);
				tracker.SendMessage(&openMsg);
			}
		}
		break;
		case B_SIMPLE_DATA:
		case B_REFS_RECEIVED:
		case B_PASTE:
		case B_MODIFIERS_CHANGED:
			break;
		default:
			BWindow::MessageReceived(message);
			break;
	}
}
void TransfersManager::transferFinished()
{
	Transfer *transfer = qobject_cast<Transfer*>(sender());

	if (transfer)
	{
		if (transfer->getState() == Transfer::FinishedState)
		{
			connect(NotificationsManager::createNotification(NotificationsManager::TransferCompletedEvent, tr("Transfer completed:\n%1").arg(QFileInfo(transfer->getTarget()).fileName()), Notification::InformationLevel, this), SIGNAL(clicked()), transfer, SLOT(openTarget()));
		}

		emit transferFinished(transfer);

		if (!m_privateTransfers.contains(transfer))
		{
			scheduleSave();
		}
	}
}