Set as caller image implementation by crop mode fit-to-screen
authorchitta ranjan <chitta.rs@samsung.com>
Mon, 8 Apr 2013 03:47:20 +0000 (12:47 +0900)
committerchitta ranjan <chitta.rs@samsung.com>
Mon, 8 Apr 2013 03:47:20 +0000 (12:47 +0900)
Change-Id: I544605c36337acdb53d576e21fcf365b47ca5266
Signed-off-by: chitta ranjan <chitta.rs@samsung.com>
src/IvImageCropForm.cpp

index a924685..a7e1148 100644 (file)
@@ -330,12 +330,10 @@ ImageCropForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
                        }
                        ArrayList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
                        pList->Add(new (std::nothrow) String(destFilePath));
-                       AppLog("Manish %ls", destFilePath.GetPointer());
                        pSceneManager->GoBackward(BackwardSceneTransition(), pList);
                }
                else if(__cropMode == "fit-to-screen")
                {
-                       AppLog("Manish OnActionPerformed");
                        ImageBuffer* pCropBuffer = null;
                        result r = E_SUCCESS;
                        pCropBuffer = __imageBuffer.CropN(((__cropBox.x - __imageBox.x) * __imageWidth) / __imageBox.width, ((__cropBox.y - __imageBox.y) * __imageHeight) / __imageBox.height,
@@ -393,20 +391,49 @@ ImageCropForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
                        }
                        else if (__statusValue == SET_AT_TYPE_CALLER_IMAGE)
                        {
+                               int count = 1;
+                               int index = 0;
+                               String destFilePath;
+                               String stringToInsert = L"_";
+                               String delimiter = L".";
+                               if (__sourceFilePath.IsEmpty() == false)
+                               {
+                                       __sourceFilePath.Reverse();
+                                       __sourceFilePath.IndexOf(delimiter, 0, index);
+                                       __sourceFilePath.Reverse();
+                                       __sourceFilePath.Insert(stringToInsert, __sourceFilePath.GetLength() - index - 1);
+                                       destFilePath.Append(__sourceFilePath);
+                                       destFilePath.Insert(count, destFilePath.GetLength() - index - 1);
+                                       while (File::IsFileExist(destFilePath) == true)
+                                       {
+                                               count++;
+                                               destFilePath.Clear();
+                                               destFilePath.Append(__sourceFilePath);
+                                               destFilePath.Insert(count, destFilePath.GetLength() - index - 1);
+                                       }
+                               }
+                                r = pCropBuffer->EncodeToFile(destFilePath, __imageFormat, true, 100);
+                               ContentManager::ScanFile(destFilePath);
                                Contact* pContact = null;
                                AddressbookManager* pAddressbookManager = AddressbookManager::GetInstance();
                                Addressbook* pAddressbook = null;
 
                                pAddressbook = pAddressbookManager->GetAddressbookN(DEFAULT_ADDRESSBOOK_ID);
                                pContact = pAddressbook->GetContactN(__contentId);
-                               pContact->SetThumbnail(__sourceFilePath);
+                               pContact->SetThumbnail(destFilePath);
                                pAddressbook->UpdateContact(*pContact);
 
                                delete pContact;
                                delete pAddressbook;
+                               delete pCropBuffer;
+                               ArrayList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
+                               pList->Add(new (std::nothrow) String(destFilePath));
+                               pSceneManager->GoBackward(BackwardSceneTransition(), pList);
+                               AppLog("Exit");
+                               return;
                        }
                        delete pCropBuffer;
-                       pSceneManager->GoForward(ForwardSceneTransition(IDSCN_IMAGE_VIEWER));
+                       pSceneManager->GoBackward(BackwardSceneTransition());
                }
        }
        break;
@@ -566,7 +593,6 @@ ImageCropForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graph
        }
        else if (__cropMode != "auto")
        {
-               //AppLog("Manish Fit to screen");
                if (__pointLocation == INSIDE_LEFT_RECTANGLE || __pointLocation == INSIDE_BOTTOM_LEFT_RECTANGLE
                        || __pointLocation == INSIDE_TOP_LEFT_RECTANGLE)
                {
@@ -579,7 +605,6 @@ ImageCropForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graph
                                        && __cropBox.y - (temp / 2) >= __imageBox.y && __cropBox.y + __cropBox.height + (temp / 2) < __imageBox.y + __imageBox.height
                                        && (__cropBox.width - (2 * deltaX) > (CROP_RECTANGLE_HEIGHT * 3)))
                                {
-                                       AppLog("Manish 0");
                                        __cropBox.x += deltaX;
                                        __cropBox.width = __cropBox.width - (2 * deltaX);
                                        __cropBox.height = height;
@@ -589,16 +614,13 @@ ImageCropForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graph
                                                && __cropBox.width < __imageBox.width
                                                && __cropBox.x + deltaX >= __imageBox.x && __cropBox.y - temp >= __imageBox.y )
                                {
-                                       AppLog("Manish 1");
                                        if (__cropBox.x + __cropBox.width - deltaX <= __imageBox.x + __imageBox.width
                                                && __cropBox.x + deltaX >= __imageBox.x)
                                        {
-                                               //AppLog("Manish 2");
                                                __cropBox.x += deltaX;
                                        }
                                        else
                                        {
-                                               AppLog("Manish 3");
                                                __cropBox.x = __cropBox.x + (2 * deltaX);
                                        }
                                        __cropBox.width = __cropBox.width - (2 * deltaX);
@@ -610,12 +632,10 @@ ImageCropForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graph
                                {
                                        if (__cropBox.x + __cropBox.width - deltaX <= __imageBox.x + __imageBox.width)
                                        {
-                                               AppLog("Manish 4");
                                                __cropBox.x += deltaX;
                                        }
                                        else
                                        {
-                                               AppLog("Manish 5");
                                                __cropBox.x = __cropBox.x + (2 * deltaX);
                                        }
                                        __cropBox.width = __cropBox.width - (2 * deltaX);
@@ -638,7 +658,6 @@ ImageCropForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graph
                                        if (__cropBox.x + deltaX > __imageBox.x && __cropBox.x + __cropBox.width - deltaX <= __imageBox.x + __imageBox.width
                                                && __cropBox.y - (temp / 2) > __imageBox.y && __cropBox.y + __cropBox.height + (temp / 2) < __imageBox.y + __imageBox.height)
                                        {
-                                               AppLog("Manish 0");
                                                __cropBox.x += deltaX;
                                                __cropBox.width = __cropBox.width - (2 * deltaX);;
                                                __cropBox.height = height;
@@ -648,16 +667,13 @@ ImageCropForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graph
                                                        && __cropBox.x + __cropBox.width - (2 * deltaX) <= __imageBox.x + __imageBox.width
                                                        && __cropBox.x - deltaX >= __imageBox.x && __cropBox.y - temp >= __imageBox.y )
                                        {
-                                                       AppLog("Manish 1");
                                                if (__cropBox.x + __cropBox.width - deltaX <= __imageBox.x + __imageBox.width
                                                        && __cropBox.x + deltaX >= __imageBox.x)
                                                {
-                                                       AppLog("Manish 2");
                                                        __cropBox.x += deltaX;
                                                }
                                                else
                                                {
-                                                       AppLog("Manish 3");
                                                        __cropBox.width = __cropBox.width - (2 * deltaX);
                                                }
                                                __cropBox.width = __cropBox.width - (2 * deltaX);
@@ -667,10 +683,8 @@ ImageCropForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graph
                                        else if (__cropBox.y - (temp / 2) <= __imageBox.y && __cropBox.width - (deltaX) <= __imageBox.width
                                                        && __cropBox.x + deltaX <= __imageBox.x && __cropBox.y + __cropBox.height + temp <= __imageBox.y + __imageBox.height)
                                        {
-                                               AppLog("Manish 25");
                                                if (__cropBox.x + deltaX >= __imageBox.x)
                                                {
-                                                       AppLog("Manish 4");
                                                        __cropBox.x += deltaX;
                                                }
                                                else
@@ -684,7 +698,6 @@ ImageCropForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graph
                                                        && __cropBox.x + __cropBox.width - deltaX <= __imageBox.x + __imageBox.width
                                                        && __cropBox.y + __cropBox.height + temp <= __imageBox.y + __imageBox.height)
                                        {
-                                               AppLog("Manish 999");
                                                __cropBox.x += deltaX;
                                                __cropBox.width = __cropBox.width - (2 * deltaX);
                                                __cropBox.height = height;
@@ -710,7 +723,6 @@ ImageCropForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graph
                                if (__cropBox.x - (temp /2 ) > __imageBox.x && __cropBox.x + __cropBox.width + temp < __imageBox.x + __imageBox.width
                                        && __cropBox.y + (deltaY) > __imageBox.y && __cropBox.y + __cropBox.height - (2 * deltaY) < __imageBox.y + __imageBox.height)
                                {
-                                       AppLog("Manish 0");
                                        __cropBox.y += deltaY;
                                        __cropBox.height = __cropBox.height - (2 * deltaY);
                                        __cropBox.width = width;
@@ -718,7 +730,6 @@ ImageCropForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graph
                                }
                                else if (__cropBox.x - (temp / 2) < __imageBox.x)
                                {
-                                       AppLog("manish 55");
                                        if (__cropBox.x + __cropBox.width + temp <= __imageBox.x + __imageBox.width)
                                        {
                                                __cropBox.width = width;
@@ -729,14 +740,12 @@ ImageCropForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graph
                                        }
                                        if (__cropBox.y + __cropBox.height - (2 * deltaY) < __imageBox.y + __imageBox.height)
                                        {
-                                               AppLog("Manish 56");
                                                __cropBox.height = __cropBox.height - (2 * deltaY);
                                        }
                                }
                                else if (__cropBox.y + __cropBox.height - (2 * deltaY) >= __imageBox.x + __imageBox.height
                                                && __cropBox.y + (2 * deltaY) >= __imageBox.y)
                                {
-                                       AppLog("Manish 1");
                                        if (__cropBox.x - temp >= __imageBox.x
                                                && __cropBox.x + __cropBox.width + temp > __imageBox.x + __imageBox.width)
                                        {
@@ -760,7 +769,6 @@ ImageCropForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graph
                                                && __cropBox.x - temp >= __imageBox.x && __cropBox.y + deltaY >= __imageBox.y
                                                && __cropBox.y + __cropBox.height - (2 * deltaY) <= __imageBox.y + __imageBox.height)
                                {
-                                       AppLog("manish 58");
                                        __cropBox.x = __cropBox.x - temp;
                                        __cropBox.width = width;
                                        __cropBox.y += deltaY;
@@ -770,7 +778,6 @@ ImageCropForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graph
                }
                else if (__pointLocation == INSIDE_BOTTOM_RECTANGLE)
                {
-                       AppLog("Manish INSIDE BOTTOM RECTANGLE");
                        deltaY = deltaY * (-1);
                        int temp = __cropBox.width;
                        int width = (__formWidth * (__cropBox.height - (2 * deltaY))) / __formHeight;
@@ -780,7 +787,6 @@ ImageCropForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graph
                                if (__cropBox.x - (temp / 2) >= __imageBox.x && __cropBox.x + __cropBox.width + temp < __imageBox.x + __imageBox.width
                                        && __cropBox.y + deltaY > __imageBox.y && __cropBox.y + __cropBox.height - (2 * deltaY) < __imageBox.y + __imageBox.height)
                                {
-                                       AppLog("Manish 0");
                                        __cropBox.y += deltaY;
                                        __cropBox.height = __cropBox.height - (2 * deltaY);;
                                        __cropBox.width = width;
@@ -789,7 +795,6 @@ ImageCropForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graph
                                else if (__cropBox.y + deltaY < __imageBox.y && __cropBox.y + __cropBox.height - (2 * deltaY) < __imageBox.y + __imageBox.height
                                                && __cropBox.x - (temp / 2) > __imageBox.x && __cropBox.x + __cropBox.width + temp < __imageBox.x + __imageBox.width)
                                {
-                                       AppLog("Manish 1");
                                        __cropBox.x = __cropBox.x - (temp / 2);
                                        __cropBox.width = width;
                                        __cropBox.height = __cropBox.height - (2 * deltaY);
@@ -798,7 +803,6 @@ ImageCropForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graph
                                                && __cropBox.y + deltaY >= __imageBox.y && __cropBox.y + __cropBox.height + temp <= __imageBox.y + __imageBox.height
                                                && __cropBox.x - temp >= __imageBox.x)
                                {
-                                       AppLog("Manish 2");
                                        __cropBox.x = __cropBox.x - temp;
                                        __cropBox.y += deltaY;
                                        __cropBox.width = width;
@@ -808,7 +812,6 @@ ImageCropForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graph
                                                && __cropBox.y + deltaY <= __imageBox.y && __cropBox.x - temp > __imageBox.x
                                                && __cropBox.y + __cropBox.height + temp < __imageBox.y + __imageBox.height)
                                {
-                                       AppLog("Manish 3");
                                        __cropBox.x -= temp;
                                        __cropBox.width = width;
                                        __cropBox.height = __cropBox.height - (2 * deltaY);
@@ -816,7 +819,6 @@ ImageCropForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graph
                                else if (__cropBox.x - temp < __imageBox.x && __cropBox.x + __cropBox.width + temp <= __imageBox.x + __imageBox.width
                                                && __cropBox.y + __cropBox.height - (2 * deltaY) <= __imageBox.y + __imageBox.height)
                                {
-                                       AppLog("manish 4");
                                        if (__cropBox.y + deltaY >= __imageBox.y)
                                        {
                                                __cropBox.y += deltaY;
@@ -940,11 +942,8 @@ ImageCropForm::SetValue(void)
                __formHeight = Form::GetBounds().width;
                __formWidth = Form::GetBounds().height;
        }
-       AppLog("Manish h value %d", __formHeight);
-       AppLog("Manish w value %d", __formWidth);
 
        float clientAreaRatio = (GetClientAreaBoundsF().height - FOOTER_PANEL_HEIGHT) / GetClientAreaBoundsF().width;
-       AppLog("Manish %f", clientAreaRatio);
        if (__imageWidth >= GetClientAreaBounds().width || __imageHeight > (GetClientAreaBounds().height - FOOTER_PANEL_HEIGHT))
        {
                float imageRatio = __imageHeight / (float) __imageWidth;
@@ -1008,8 +1007,6 @@ ImageCropForm::SetValue(void)
                temp = (__cropBox.width * __imageBox.width) / (float)prevWidth;
                __cropBox.width = (temp + 0.5);
        }
-       AppLog("Manish %d %d", __imageBox.width, __imageBox.height);
-       AppLog("Manish %d %d", __cropBox.width, __cropBox.height);
        __pCanvas = GetCanvasN();
        __pCanvas->SetForegroundColor(CROP_BOX_RECTANGLE_COLOR);
 }
@@ -1017,9 +1014,6 @@ ImageCropForm::SetValue(void)
 void ImageCropForm::OnFormFileEventOccuered(const int index, const unsigned long eventId)
 {
        AppLogDebug(" ENTER");
-       if (File::IsFileExist(__sourceFilePath) == false)
-       {
-               UiApp::GetInstance()->Terminate();
-       }
+       UiApp::GetInstance()->Terminate();
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
 }