hrev43661 adds 2 changesets to branch 'master' old head: f35fa32b3a797adc7f93d39dddefa8ec92cf81ef new head: 1a7322a09e825d2445ca88a47cd1d5cd06d3811b ---------------------------------------------------------------------------- cd8bd6f: Preserve/Restore e-mail reading position * Introduce the "MAIL:read_pos" attribute of e-mail file node to store the latest scroll position of the mail text view; * Fixes #4302 (Mail should store and restore scroll offset); * This feature was implemented during completing GCI2011 task. Signed-off-by: Siarzhuk Zharski <zharik@xxxxxx> 1a7322a: Command line 'writembr' tool implemented * Implemented writembr tool used to update MBR area with easy boot loader starting the system from currently active partition; * This work fixes #5595; * This is result of GCI2011 task. Signed-off-by: Siarzhuk Zharski <zharik@xxxxxx> [ Aleksas Pantechovskis <alexp.frl@xxxxxxxxx> ] ---------------------------------------------------------------------------- 8 files changed, 197 insertions(+), 1 deletions(-) build/jam/HaikuImage | 3 +- src/apps/mail/Content.cpp | 3 + src/apps/mail/MailWindow.cpp | 36 +++++++++++ src/apps/mail/MailWindow.h | 1 + src/apps/mail/Messages.h | 1 + src/bin/Jamfile | 1 + src/bin/writembr/Jamfile | 28 ++++++++ src/bin/writembr/writembr.cpp | 125 +++++++++++++++++++++++++++++++++++++ ############################################################################ Commit: cd8bd6fa3fd3871812cc3e4027e15ca11e1adeaa URL: http://cgit.haiku-os.org/haiku/commit/?id=cd8bd6f Author: Aleksas Pantechovskis <alexp.frl@xxxxxxxxx> Date: Thu Jan 12 22:00:46 2012 UTC Committer: Siarzhuk Zharski <zharik@xxxxxx> Commit-Date: Sun Jan 15 15:03:17 2012 UTC Ticket: https://dev.haiku-os.org/ticket/4302 Preserve/Restore e-mail reading position * Introduce the "MAIL:read_pos" attribute of e-mail file node to store the latest scroll position of the mail text view; * Fixes #4302 (Mail should store and restore scroll offset); * This feature was implemented during completing GCI2011 task. Signed-off-by: Siarzhuk Zharski <zharik@xxxxxx> ---------------------------------------------------------------------------- diff --git a/src/apps/mail/Content.cpp b/src/apps/mail/Content.cpp index d8e45c0..b0c90c6 100644 --- a/src/apps/mail/Content.cpp +++ b/src/apps/mail/Content.cpp @@ -2622,6 +2622,9 @@ TTextView::Reader::Run(void *_this) } done: + // restore the reading position if available + view->Window()->PostMessage(M_READ_POS); + reader->Unlock(); delete reader; diff --git a/src/apps/mail/MailWindow.cpp b/src/apps/mail/MailWindow.cpp index e204cb8..1822886 100644 --- a/src/apps/mail/MailWindow.cpp +++ b/src/apps/mail/MailWindow.cpp @@ -795,6 +795,31 @@ TMailWindow::SetTrackerSelectionToCurrent() void +TMailWindow::PreserveReadingPos(bool save) +{ + BScrollBar *scroll = fContentView->fTextView->ScrollBar(B_VERTICAL); + if (scroll == NULL || fRef == NULL) + return; + + BNode node(fRef); + float pos = scroll->Value(); + + const char* name = "MAIL:read_pos"; + if (save) { + node.WriteAttr(name, B_FLOAT_TYPE, 0, &pos, sizeof(pos)); + syslog(0, "save: %f", pos); + return; + } + + if (node.ReadAttr(name, B_FLOAT_TYPE, 0, &pos, sizeof(pos)) == sizeof(pos)) { + Lock(); + scroll->SetValue(pos); + Unlock(); + } +} + + +void TMailWindow::MarkMessageRead(entry_ref* message, read_flags flag) { BNode node(message); @@ -810,6 +835,9 @@ TMailWindow::MarkMessageRead(entry_ref* message, read_flags flag) // don't wait for the server write the attribute directly write_read_attr(node, flag); + // preserve the read position in the node attribute + PreserveReadingPos(true); + BMailDaemon::MarkAsRead(account, *message, flag); } @@ -1337,6 +1365,10 @@ TMailWindow::MessageReceived(BMessage *msg) break; } + case M_READ_POS: + PreserveReadingPos(false); + break; + case M_PRINT_SETUP: PrintSetup(); break; @@ -2848,6 +2880,10 @@ TMailWindow::OpenMessage(const entry_ref *ref, uint32 characterSetForDecoding) } AddEnclosure(&msg); } + + // restore the reading position if available + PostMessage(M_READ_POS); + PostMessage(RESET_BUTTONS); fIncoming = false; fDraft = true; diff --git a/src/apps/mail/MailWindow.h b/src/apps/mail/MailWindow.h index 00f91e1..d2a2c90 100644 --- a/src/apps/mail/MailWindow.h +++ b/src/apps/mail/MailWindow.h @@ -108,6 +108,7 @@ class TMailWindow : public BWindow { void SaveTrackerPosition(entry_ref*); void SetOriginatingWindow(BWindow* window); + void PreserveReadingPos(bool save); void MarkMessageRead(entry_ref* message, read_flags flag); void SetTrackerSelectionToCurrent(); diff --git a/src/apps/mail/Messages.h b/src/apps/mail/Messages.h index 1f304f0..a98b06a 100644 --- a/src/apps/mail/Messages.h +++ b/src/apps/mail/Messages.h @@ -86,6 +86,7 @@ enum MENUS { M_CLOSE_SAVED, M_CLOSE_CUSTOM, M_STATUS, + M_READ_POS, // edit M_SELECT, ############################################################################ Revision: hrev43661 Commit: 1a7322a09e825d2445ca88a47cd1d5cd06d3811b URL: http://cgit.haiku-os.org/haiku/commit/?id=1a7322a Author: Aleksas Pantechovskis <alexp.frl@xxxxxxxxx> Date: Sun Jan 15 14:51:33 2012 UTC Committer: Siarzhuk Zharski <zharik@xxxxxx> Commit-Date: Sun Jan 15 15:03:24 2012 UTC Ticket: https://dev.haiku-os.org/ticket/5595 Command line 'writembr' tool implemented * Implemented writembr tool used to update MBR area with easy boot loader starting the system from currently active partition; * This work fixes #5595; * This is result of GCI2011 task. Signed-off-by: Siarzhuk Zharski <zharik@xxxxxx> ---------------------------------------------------------------------------- diff --git a/build/jam/HaikuImage b/build/jam/HaikuImage index 972856d..3573caa 100644 --- a/build/jam/HaikuImage +++ b/build/jam/HaikuImage @@ -60,7 +60,8 @@ SYSTEM_BIN = "[" addattr alert arp base64 basename bash bc beep bzip2 tput tr traceroute translate trash true truncate tsort tty uname unchop unexpand unmount uniq unlink unrar unshar unzip unzipsfx <bin>updatedb uptime urlwrapper useradd uudecode uuencode - vdir version vmstat waitfor watch wc wget whoami xargs xres yes + vdir version vmstat + waitfor watch wc wget whoami $(X86_ONLY)writembr xargs xres yes zdiff zforce zgrep zip zipcloak <bin>zipgrep zipnote zipsplit zmore znew ; diff --git a/src/bin/Jamfile b/src/bin/Jamfile index 4dc153e..ffa2844 100644 --- a/src/bin/Jamfile +++ b/src/bin/Jamfile @@ -276,6 +276,7 @@ SubInclude HAIKU_TOP src bin screen_blanker ; SubInclude HAIKU_TOP src bin screenmode ; SubInclude HAIKU_TOP src bin sharutils ; SubInclude HAIKU_TOP src bin unrar ; +SubInclude HAIKU_TOP src bin writembr ; SubInclude HAIKU_TOP src bin zic ; # RCS commands diff --git a/src/bin/writembr/Jamfile b/src/bin/writembr/Jamfile new file mode 100644 index 0000000..1979c60 --- /dev/null +++ b/src/bin/writembr/Jamfile @@ -0,0 +1,28 @@ +SubDir HAIKU_TOP src bin writembr ; + +UsePrivateHeaders shared storage ; + +Application writembr : + writembr.cpp + + : be $(TARGET_LIBSUPC+++) $(TARGET_LIBSTDC++) +; + +# Assemble the MBR code, and convert it into a header file + +rule AssembleYasmBin object : source +{ + SEARCH on $(source) = $(SUBDIR) ; + MakeLocateDebug $(object) ; + Depends $(object) : $(source) ; +} + +actions AssembleYasmBin +{ + $(HAIKU_YASM) -f bin -O5 -o $(1) $(2) +} + +AssembleYasmBin [ FGristFiles mbr.bin ] : mbr.S ; + +DataFileToSourceFile [ FGristFiles MBR.h ] : [ FGristFiles mbr.bin ] + : kMBR : kMBRSize ; diff --git a/src/bin/writembr/writembr.cpp b/src/bin/writembr/writembr.cpp new file mode 100644 index 0000000..269edec --- /dev/null +++ b/src/bin/writembr/writembr.cpp @@ -0,0 +1,125 @@ +/* + * Copyright 2012 Aleksas Pantechovskis, <alexp.frl@xxxxxxxxx> + * All rights reserved. Distributed under the terms of the MIT License. + */ + +#include <fstream> +#include <iostream> +#include <sstream> +#include <string.h> +#include <string> + +#include <DiskDevice.h> +#include <DiskDeviceRoster.h> +#include <Path.h> +#include <Volume.h> +#include <VolumeRoster.h> + +#include "MBR.h" + + +using namespace std; + +const char* kUsageMessage = \ + "Usage: writembr [ device ] \n" + "#\tRewrites the MBR for the specified device.\n" + "#\tIf no device is specified, the boot device is used.\n" + "#\t--help shows this usage message\n"; + + +int +main(int argc, char** argv) +{ + status_t result = B_ERROR; + + if ((argc == 2 && strcmp(argv[1], "--help") == 0) || argc > 2) { + cerr << kUsageMessage; + return result; + } + + BPath device; + + if (argc == 2) + // user specified device for rewriting + device.SetTo(argv[1]); + + else if (argc == 1) { + // no parameters specified, rewrite boot device + BVolumeRoster volumeRoster; + BVolume bootVolume; + if (volumeRoster.GetBootVolume(&bootVolume) != B_OK) { + cerr << "Can not find boot device" << endl; + return result; + } + + BDiskDeviceRoster roster; + BDiskDevice bootDevice; + if(roster.FindPartitionByVolume(bootVolume, &bootDevice, NULL) != B_OK) { + cerr << "Can not find boot device" << endl; + return result; + } + + bootDevice.GetPath(&device); + } + + + if (strcmp(device.Leaf(), "raw") != 0) { + cerr << device.Path() << " is not a raw device" << endl; + return result; + } + + fstream fs; + fs.exceptions(ios::failbit | ios::badbit); + + try { + + fs.open(device.Path(), fstream::in | fstream::out | fstream::binary); + + unsigned char MBR[kMBRSize]; + fs.read((char*)MBR, kMBRSize); + if (fs.gcount() < kMBRSize ) { + stringstream error; + error << "only " << fs.gcount() << " of " << kMBRSize + << " bytes was read from " << device.Path(); + throw fstream::failure(error.str()); + } + + // update only the code area and the MBR signature + memcpy(MBR, kMBR, 0x1be); + MBR[0x1FE] = kMBR[0x1FE]; + MBR[0x1FF] = kMBR[0x1FF]; + + cerr << "About to overwrite the MBR boot code on " << device.Path() + << "\nThis may disable any partition managers you have installed.\n" + << "Are you sure you want to continue?\nyes/[no]: "; + + string choice; + getline(cin, choice, '\n'); + if (choice == "no" || choice == "" || choice != "yes") + throw fstream::failure("users cancel"); + + cerr << "Rewriting MBR for " << device.Path() << endl; + + fs.seekg(0, ios::beg); + fs.write((char*)MBR, kMBRSize); + fs.flush(); + + cerr << "MBR was written OK" << endl; + result = B_OK; + + } catch (fstream::failure exception) { + cerr << "MBR was NOT written" << endl; + cerr << "Error: "; + if (fs.is_open()) + cerr << exception.what(); + else + cerr << "Can't open " << device.Path(); + cerr << endl; + } + + if (fs.is_open()) + fs.close(); + + return result; +} +