summaryrefslogtreecommitdiff
path: root/indra/newview/llpanelprofilepicks.cpp
blob: 8bbd4a748dfd59e3d67ff05dcc70654c30aca6ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
/**
 * @file llpanelprofilepicks.cpp
 * @brief LLPanelProfilePicks and related class implementations
 *
 * $LicenseInfo:firstyear=2009&license=viewerlgpl$
 * Second Life Viewer Source Code
 * Copyright (C) 2010, Linden Research, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation;
 * version 2.1 of the License only.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 * $/LicenseInfo$
 */

#include "llviewerprecompiledheaders.h"

#include "llpanelprofilepicks.h"

#include "llagent.h"
#include "llagentpicksinfo.h"
#include "llavataractions.h"
#include "llavatarpropertiesprocessor.h"
#include "llcommandhandler.h"
#include "lldispatcher.h"
#include "llfloaterreg.h"
#include "llfloaterworldmap.h"
#include "lllineeditor.h"
#include "llnotificationsutil.h"
#include "llpanelavatar.h"
#include "llpanelprofile.h"
#include "llparcel.h"
#include "llstartup.h"
#include "lltabcontainer.h"
#include "lltextbox.h"
#include "lltexteditor.h"
#include "lltexturectrl.h"
#include "lltexturectrl.h"
#include "lltrans.h"
#include "llviewergenericmessage.h" // send_generic_message
#include "llviewerparcelmgr.h"
#include "llviewerregion.h"

static LLPanelInjector<LLPanelProfilePicks> t_panel_profile_picks("panel_profile_picks");
static LLPanelInjector<LLPanelProfilePick> t_panel_profile_pick("panel_profile_pick");


class LLPickHandler : public LLCommandHandler
{
public:

    // requires trusted browser to trigger
    LLPickHandler() : LLCommandHandler("pick", UNTRUSTED_THROTTLE) { }

    virtual bool canHandleUntrusted(
        const LLSD& params,
        const LLSD& query_map,
        LLMediaCtrl* web,
        const std::string& nav_type)
    {
        if (params.size() < 1)
        {
            return true; // don't block, will fail later
        }

        if (nav_type == NAV_TYPE_CLICKED
            || nav_type == NAV_TYPE_EXTERNAL)
        {
            return true;
        }

        const std::string verb = params[0].asString();
        if (verb == "create")
        {
            return false;
        }
        return true;
    }

    bool handle(const LLSD& params,
                const LLSD& query_map,
                const std::string& grid,
                LLMediaCtrl* web)
    {
        if (LLStartUp::getStartupState() < STATE_STARTED)
        {
            return true;
        }

        if (!LLUI::getInstance()->mSettingGroups["config"]->getBOOL("EnablePicks"))
        {
            LLNotificationsUtil::add("NoPicks", LLSD(), LLSD(), std::string("SwitchToStandardSkinAndQuit"));
            return true;
        }

        // handle app/pick/create urls first
        if (params.size() == 1 && params[0].asString() == "create")
        {
            LLAvatarActions::createPick();
            return true;
        }

        // then handle the general app/pick/{UUID}/{CMD} urls
        if (params.size() < 2)
        {
            return false;
        }

        // get the ID for the pick_id
        LLUUID pick_id;
        if (!pick_id.set(params[0], FALSE))
        {
            return false;
        }

        // edit the pick in the side tray.
        // need to ask the server for more info first though...
        const std::string verb = params[1].asString();
        if (verb == "edit")
        {
            LLAvatarActions::showPick(gAgent.getID(), pick_id);
            return true;
        }
        else
        {
            LL_WARNS() << "unknown verb " << verb << LL_ENDL;
            return false;
        }
    }
};
LLPickHandler gPickHandler;


//-----------------------------------------------------------------------------
// LLPanelProfilePicks
//-----------------------------------------------------------------------------

LLPanelProfilePicks::LLPanelProfilePicks()
 : LLPanelProfilePropertiesProcessorTab()
 , mPickToSelectOnLoad(LLUUID::null)
{
}

LLPanelProfilePicks::~LLPanelProfilePicks()
{
}

void LLPanelProfilePicks::onOpen(const LLSD& key)
{
    LLPanelProfilePropertiesProcessorTab::onOpen(key);

    resetData();

    bool own_profile = getSelfProfile();
    if (own_profile)
    {
        mNewButton->setVisible(TRUE);
        mNewButton->setEnabled(FALSE);

        mDeleteButton->setVisible(TRUE);
        mDeleteButton->setEnabled(FALSE);
    }

    childSetVisible("buttons_header", own_profile);
}

void LLPanelProfilePicks::createPick(const LLPickData &data)
{
    if (getIsLoaded())
    {
        if (canAddNewPick())
        {
            mNoItemsLabel->setVisible(FALSE);
            LLPanelProfilePick* pick_panel = LLPanelProfilePick::create();
            pick_panel->setAvatarId(getAvatarId());
            pick_panel->processProperties(&data);
            mTabContainer->addTabPanel(
                LLTabContainer::TabPanelParams().
                panel(pick_panel).
                select_tab(true).
                label(pick_panel->getPickName()));
            updateButtons();
        }
        else
        {
            // This means that something doesn't properly check limits
            // before creating a pick
            LL_WARNS() << "failed to add pick" << LL_ENDL;
        }
    }
    else
    {
        mSheduledPickCreation.push_back(data);
    }
}

void LLPanelProfilePicks::selectPick(const LLUUID& pick_id)
{
    if (getIsLoaded())
    {
        for (S32 tab_idx = 0; tab_idx < mTabContainer->getTabCount(); ++tab_idx)
        {
            LLPanelProfilePick* pick_panel = dynamic_cast<LLPanelProfilePick*>(mTabContainer->getPanelByIndex(tab_idx));
            if (pick_panel)
            {
                if (pick_panel->getPickId() == pick_id)
                {
                    mTabContainer->selectTabPanel(pick_panel);
                    break;
                }
            }
        }
    }
    else
    {
        mPickToSelectOnLoad = pick_id;
    }
}

BOOL LLPanelProfilePicks::postBuild()
{
    mTabContainer = getChild<LLTabContainer>("tab_picks");
    mNoItemsLabel = getChild<LLUICtrl>("picks_panel_text");
    mNewButton = getChild<LLButton>("new_btn");
    mDeleteButton = getChild<LLButton>("delete_btn");

    mNewButton->setCommitCallback(boost::bind(&LLPanelProfilePicks::onClickNewBtn, this));
    mDeleteButton->setCommitCallback(boost::bind(&LLPanelProfilePicks::onClickDelete, this));

    return TRUE;
}

void LLPanelProfilePicks::onClickNewBtn()
{
    mNoItemsLabel->setVisible(FALSE);
    LLPanelProfilePick* pick_panel = LLPanelProfilePick::create();
    pick_panel->setAvatarId(getAvatarId());
    mTabContainer->addTabPanel(
        LLTabContainer::TabPanelParams().
        panel(pick_panel).
        select_tab(true).
        label(pick_panel->getPickName()));
    updateButtons();
}

void LLPanelProfilePicks::onClickDelete()
{
    LLPanelProfilePick* pick_panel = dynamic_cast<LLPanelProfilePick*>(mTabContainer->getCurrentPanel());
    if (pick_panel)
    {
        LLUUID pick_id = pick_panel->getPickId();
        LLSD args;
        args["PICK"] = pick_panel->getPickName();
        LLSD payload;
        payload["pick_id"] = pick_id;
        payload["tab_idx"] = mTabContainer->getCurrentPanelIndex();
        LLNotificationsUtil::add("ProfileDeletePick", args, payload,
            boost::bind(&LLPanelProfilePicks::callbackDeletePick, this, _1, _2));
    }
}

void LLPanelProfilePicks::callbackDeletePick(const LLSD& notification, const LLSD& response)
{
    S32 option = LLNotificationsUtil::getSelectedOption(notification, response);

    if (0 == option)
    {
        LLUUID pick_id = notification["payload"]["pick_id"].asUUID();
        S32 tab_idx = notification["payload"]["tab_idx"].asInteger();

        LLPanelProfilePick* pick_panel = dynamic_cast<LLPanelProfilePick*>(mTabContainer->getPanelByIndex(tab_idx));
        if (pick_panel && pick_panel->getPickId() == pick_id)
        {
            mTabContainer->removeTabPanel(pick_panel);
        }

        if (pick_id.notNull())
        {
            LLAvatarPropertiesProcessor::getInstance()->sendPickDelete(pick_id);
        }

        updateButtons();
    }
}

void LLPanelProfilePicks::processProperties(void* data, EAvatarProcessorType type)
{
    if (APT_PICKS == type)
    {
        LLAvatarPicks* avatar_picks = static_cast<LLAvatarPicks*>(data);
        if (avatar_picks && getAvatarId() == avatar_picks->target_id)
        {
            processProperties(avatar_picks);
        }
    }
}

void LLPanelProfilePicks::processProperties(const LLAvatarPicks* avatar_picks)
{
    LLUUID selected_id = mPickToSelectOnLoad;
    bool has_selection = false;
    if (mPickToSelectOnLoad.isNull())
    {
        if (mTabContainer->getTabCount() > 0)
        {
            LLPanelProfilePick* active_pick_panel = dynamic_cast<LLPanelProfilePick*>(mTabContainer->getCurrentPanel());
            if (active_pick_panel)
            {
                selected_id = active_pick_panel->getPickId();
            }
        }
    }

    mTabContainer->deleteAllTabs();

    LLAvatarPicks::picks_list_t::const_iterator it = avatar_picks->picks_list.begin();
    for (; avatar_picks->picks_list.end() != it; ++it)
    {
        LLUUID pick_id = it->first;
        std::string pick_name = it->second;

        LLPanelProfilePick* pick_panel = LLPanelProfilePick::create();

        pick_panel->setPickId(pick_id);
        pick_panel->setPickName(pick_name);
        pick_panel->setAvatarId(getAvatarId());

        mTabContainer->addTabPanel(
            LLTabContainer::TabPanelParams().
            panel(pick_panel).
            select_tab(selected_id == pick_id).
            label(pick_name));

        if (selected_id == pick_id)
        {
            has_selection = true;
        }
    }

    while (!mSheduledPickCreation.empty() && canAddNewPick())
    {
        const LLPickData data =
            mSheduledPickCreation.back();

        LLPanelProfilePick* pick_panel = LLPanelProfilePick::create();
        pick_panel->setAvatarId(getAvatarId());
        pick_panel->processProperties(&data);
        mTabContainer->addTabPanel(
            LLTabContainer::TabPanelParams().
            panel(pick_panel).
            select_tab(!has_selection).
            label(pick_panel->getPickName()));

        mSheduledPickCreation.pop_back();
        has_selection = true;
    }

    // reset 'do on load' values
    mPickToSelectOnLoad = LLUUID::null;
    mSheduledPickCreation.clear();

    if (getSelfProfile())
    {
        mNoItemsLabel->setValue(LLTrans::getString("NoPicksText"));
    }
    else
    {
        mNoItemsLabel->setValue(LLTrans::getString("NoAvatarPicksText"));
    }

    bool has_data = mTabContainer->getTabCount() > 0;
    mNoItemsLabel->setVisible(!has_data);
    if (has_data && !has_selection)
    {
        mTabContainer->selectFirstTab();
    }

    setLoaded();
    updateButtons();
}

void LLPanelProfilePicks::resetData()
{
    resetLoading();
    mTabContainer->deleteAllTabs();
}

void LLPanelProfilePicks::updateButtons()
{
    if (getSelfProfile())
    {
        mNewButton->setEnabled(canAddNewPick());
        mDeleteButton->setEnabled(canDeletePick());
    }
}

void LLPanelProfilePicks::apply()
{
    if (getIsLoaded())
    {
        for (S32 tab_idx = 0; tab_idx < mTabContainer->getTabCount(); ++tab_idx)
        {
            LLPanelProfilePick* pick_panel = dynamic_cast<LLPanelProfilePick*>(mTabContainer->getPanelByIndex(tab_idx));
            if (pick_panel)
            {
                pick_panel->apply();
            }
        }
    }
}

void LLPanelProfilePicks::updateData()
{
    // Send picks request only once
    LLUUID avatar_id = getAvatarId();
    if (!getStarted() && avatar_id.notNull())
    {
        setIsLoading();

        LLAvatarPropertiesProcessor::getInstance()->sendAvatarPicksRequest(avatar_id);
    }
    if (!getIsLoaded())
    {
        mNoItemsLabel->setValue(LLTrans::getString("PicksClassifiedsLoadingText"));
        mNoItemsLabel->setVisible(TRUE);
    }
}

bool LLPanelProfilePicks::hasUnsavedChanges()
{
    for (S32 tab_idx = 0; tab_idx < mTabContainer->getTabCount(); ++tab_idx)
    {
        LLPanelProfilePick* pick_panel = dynamic_cast<LLPanelProfilePick*>(mTabContainer->getPanelByIndex(tab_idx));
        if (pick_panel && (pick_panel->isDirty() || pick_panel->isDirty()))
        {
            return true;
        }
    }
    return false;
}

void LLPanelProfilePicks::commitUnsavedChanges()
{
    for (S32 tab_idx = 0; tab_idx < mTabContainer->getTabCount(); ++tab_idx)
    {
        LLPanelProfilePick* pick_panel = dynamic_cast<LLPanelProfilePick*>(mTabContainer->getPanelByIndex(tab_idx));
        if (pick_panel)
        {
            pick_panel->apply();
        }
    }
}

bool LLPanelProfilePicks::canAddNewPick()
{
    return (!LLAgentPicksInfo::getInstance()->isPickLimitReached() &&
        mTabContainer->getTabCount() < LLAgentPicksInfo::getInstance()->getMaxNumberOfPicks());
}

bool LLPanelProfilePicks::canDeletePick()
{
    return (mTabContainer->getTabCount() > 0);
}


//-----------------------------------------------------------------------------
// LLPanelProfilePick
//-----------------------------------------------------------------------------

LLPanelProfilePick::LLPanelProfilePick()
 : LLPanelProfilePropertiesProcessorTab()
 , LLRemoteParcelInfoObserver()
 , mSnapshotCtrl(NULL)
 , mPickId(LLUUID::null)
 , mParcelId(LLUUID::null)
 , mRequestedId(LLUUID::null)
 , mLocationChanged(false)
 , mNewPick(false)
 , mIsEditing(false)
 , mRegionCallbackConnection()
 , mParcelCallbackConnection()
{
}

//static
LLPanelProfilePick* LLPanelProfilePick::create()
{
    LLPanelProfilePick* panel = new LLPanelProfilePick();
    panel->buildFromFile("panel_profile_pick.xml");
    return panel;
}

LLPanelProfilePick::~LLPanelProfilePick()
{
    if (mParcelId.notNull())
    {
        LLRemoteParcelInfoProcessor::getInstance()->removeObserver(mParcelId, this);
    }

    if (mRegionCallbackConnection.connected())
    {
        mRegionCallbackConnection.disconnect();
    }
    if (mParcelCallbackConnection.connected())
    {
        mParcelCallbackConnection.disconnect();
    }
}

void LLPanelProfilePick::setAvatarId(const LLUUID& avatar_id)
{
    if (avatar_id.isNull())
    {
        return;
    }
    LLPanelProfilePropertiesProcessorTab::setAvatarId(avatar_id);

    // creating new Pick
    if (getPickId().isNull() && getSelfProfile())
    {
        mNewPick = true;

        setPosGlobal(gAgent.getPositionGlobal());

        LLUUID parcel_id = LLUUID::null, snapshot_id = LLUUID::null;
        std::string pick_name, pick_desc, region_name;

        LLParcel* parcel = LLViewerParcelMgr::getInstance()->getAgentParcel();
        if (parcel)
        {
            parcel_id = parcel->getID();
            pick_name = parcel->getName();
            pick_desc = parcel->getDesc();
            snapshot_id = parcel->getSnapshotID();
            mPickDescription->setParseHTML(false);
        }

        LLViewerRegion* region = gAgent.getRegion();
        if (region)
        {
            region_name = region->getName();
        }

        setParcelID(parcel_id);
        setPickName(pick_name.empty() ? region_name : pick_name);
        setPickDesc(pick_desc);
        setSnapshotId(snapshot_id);
        setPickLocation(createLocationText(getLocationNotice(), pick_name, region_name, getPosGlobal()));

        enableSaveButton(TRUE);
    }
    else
    {
        LLAvatarPropertiesProcessor::getInstance()->sendPickInfoRequest(getAvatarId(), getPickId());

        enableSaveButton(FALSE);
    }

    resetDirty();

    if (getSelfProfile())
    {
        mPickName->setEnabled(TRUE);
        mPickDescription->setEnabled(TRUE);
    }
    else
    {
        mSnapshotCtrl->setEnabled(FALSE);
    }
}

BOOL LLPanelProfilePick::postBuild()
{
    mPickName = getChild<LLLineEditor>("pick_name");
    mPickDescription = getChild<LLTextEditor>("pick_desc");
    mSaveButton = getChild<LLButton>("save_changes_btn");
    mCreateButton = getChild<LLButton>("create_changes_btn");
    mCancelButton = getChild<LLButton>("cancel_changes_btn");

    mSnapshotCtrl = getChild<LLTextureCtrl>("pick_snapshot");
    mSnapshotCtrl->setCommitCallback(boost::bind(&LLPanelProfilePick::onSnapshotChanged, this));
    mSnapshotCtrl->setAllowLocalTexture(FALSE);
    mSnapshotCtrl->setBakeTextureEnabled(FALSE);

    childSetAction("teleport_btn", boost::bind(&LLPanelProfilePick::onClickTeleport, this));
    childSetAction("show_on_map_btn", boost::bind(&LLPanelProfilePick::onClickMap, this));

    mSaveButton->setCommitCallback(boost::bind(&LLPanelProfilePick::onClickSave, this));
    mCreateButton->setCommitCallback(boost::bind(&LLPanelProfilePick::onClickSave, this));
    mCancelButton->setCommitCallback(boost::bind(&LLPanelProfilePick::onClickCancel, this));

    mPickName->setKeystrokeCallback(boost::bind(&LLPanelProfilePick::onPickChanged, this, _1), NULL);
    mPickName->setEnabled(FALSE);

    mPickDescription->setKeystrokeCallback(boost::bind(&LLPanelProfilePick::onPickChanged, this, _1));
    mPickDescription->setFocusReceivedCallback(boost::bind(&LLPanelProfilePick::onDescriptionFocusReceived, this));

    getChild<LLUICtrl>("pick_location")->setEnabled(FALSE);

    return TRUE;
}

void LLPanelProfilePick::onDescriptionFocusReceived()
{
    if (!mIsEditing && getSelfProfile())
    {
        mIsEditing = true;
        mPickDescription->setParseHTML(false);
    }
}

void LLPanelProfilePick::processProperties(void* data, EAvatarProcessorType type)
{
    if (APT_PICK_INFO != type)
    {
        return;
    }

    LLPickData* pick_info = static_cast<LLPickData*>(data);
    if (!pick_info
        || pick_info->creator_id != getAvatarId()
        || pick_info->pick_id != getPickId())
    {
        return;
    }

    processProperties(pick_info);
}

void LLPanelProfilePick::processProperties(const LLPickData* pick_info)
{
    mIsEditing = false;
    mPickDescription->setParseHTML(true);
    mParcelId = pick_info->parcel_id;
    setSnapshotId(pick_info->snapshot_id);
    if (!getSelfProfile())
    {
        mSnapshotCtrl->setEnabled(FALSE);
    }
    setPickName(pick_info->name);
    setPickDesc(pick_info->desc);
    setPosGlobal(pick_info->pos_global);

    // Send remote parcel info request to get parcel name and sim (region) name.
    sendParcelInfoRequest();

    // *NOTE dzaporozhan
    // We want to keep listening to APT_PICK_INFO because user may
    // edit the Pick and we have to update Pick info panel.
    // revomeObserver is called from onClickBack

    setLoaded();
}

void LLPanelProfilePick::apply()
{
    if ((mNewPick || getIsLoaded()) && isDirty())
    {
        sendUpdate();
    }
}

void LLPanelProfilePick::setSnapshotId(const LLUUID& id)
{
    mSnapshotCtrl->setImageAssetID(id);
    mSnapshotCtrl->setValid(TRUE);
}

void LLPanelProfilePick::setPickName(const std::string& name)
{
    mPickName->setValue(name);
    mPickNameStr = name;
}

const std::string LLPanelProfilePick::getPickName()
{
    return mPickName->getValue().asString();
}

void LLPanelProfilePick::setPickDesc(const std::string& desc)
{
    mPickDescription->setValue(desc);
}

void LLPanelProfilePick::setPickLocation(const std::string& location)
{
    getChild<LLUICtrl>("pick_location")->setValue(location);
}

void LLPanelProfilePick::onClickMap()
{
    LLFloaterWorldMap::getInstance()->trackLocation(getPosGlobal());
    LLFloaterReg::showInstance("world_map", "center");
}

void LLPanelProfilePick::onClickTeleport()
{
    if (!getPosGlobal().isExactlyZero())
    {
        gAgent.teleportViaLocation(getPosGlobal());
        LLFloaterWorldMap::getInstance()->trackLocation(getPosGlobal());
    }
}

void LLPanelProfilePick::enableSaveButton(BOOL enable)
{
    childSetVisible("save_changes_lp", enable);

    childSetVisible("save_btn_lp", enable && !mNewPick);
    childSetVisible("create_btn_lp", enable && mNewPick);
    childSetVisible("cancel_btn_lp", enable && !mNewPick);
}

void LLPanelProfilePick::onSnapshotChanged()
{
    enableSaveButton(TRUE);
}

void LLPanelProfilePick::onPickChanged(LLUICtrl* ctrl)
{
    if (ctrl && ctrl == mPickName)
    {
        updateTabLabel(mPickName->getText());
    }

    enableSaveButton(isDirty());
}

void LLPanelProfilePick::resetDirty()
{
    LLPanel::resetDirty();

    mPickName->resetDirty();
    mPickDescription->resetDirty();
    mSnapshotCtrl->resetDirty();
    mLocationChanged = false;
}

BOOL LLPanelProfilePick::isDirty() const
{
    if (mNewPick
        || LLPanel::isDirty()
        || mLocationChanged
        || mSnapshotCtrl->isDirty()
        || mPickName->isDirty()
        || mPickDescription->isDirty())
    {
        return TRUE;
    }
    return FALSE;
}

void LLPanelProfilePick::onClickSave()
{
    if (mRegionCallbackConnection.connected())
    {
        mRegionCallbackConnection.disconnect();
    }
    if (mParcelCallbackConnection.connected())
    {
        mParcelCallbackConnection.disconnect();
    }
    sendUpdate();

    mLocationChanged = false;
}

void LLPanelProfilePick::onClickCancel()
{
    updateTabLabel(mPickNameStr);
    LLAvatarPropertiesProcessor::getInstance()->sendPickInfoRequest(getAvatarId(), getPickId());
    mLocationChanged = false;
    enableSaveButton(FALSE);
}

std::string LLPanelProfilePick::getLocationNotice()
{
    static const std::string notice = getString("location_notice");
    return notice;
}

void LLPanelProfilePick::sendParcelInfoRequest()
{
    if (mParcelId != mRequestedId)
    {
        if (mRequestedId.notNull())
        {
            LLRemoteParcelInfoProcessor::getInstance()->removeObserver(mRequestedId, this);
        }
        LLRemoteParcelInfoProcessor::getInstance()->addObserver(mParcelId, this);
        LLRemoteParcelInfoProcessor::getInstance()->sendParcelInfoRequest(mParcelId);

        mRequestedId = mParcelId;
    }
}

void LLPanelProfilePick::processParcelInfo(const LLParcelData& parcel_data)
{
    setPickLocation(createLocationText(LLStringUtil::null, parcel_data.name, parcel_data.sim_name, getPosGlobal()));

    // We have received parcel info for the requested ID so clear it now.
    mRequestedId.setNull();

    if (mParcelId.notNull())
    {
        LLRemoteParcelInfoProcessor::getInstance()->removeObserver(mParcelId, this);
    }
}

void LLPanelProfilePick::sendUpdate()
{
    LLPickData pick_data;

    // If we don't have a pick id yet, we'll need to generate one,
    // otherwise we'll keep overwriting pick_id 00000 in the database.
    if (getPickId().isNull())
    {
        getPickId().generate();
    }

    pick_data.agent_id = gAgentID;
    pick_data.session_id = gAgent.getSessionID();
    pick_data.pick_id = getPickId();
    pick_data.creator_id = gAgentID;;

    //legacy var  need to be deleted
    pick_data.top_pick = FALSE;
    pick_data.parcel_id = mParcelId;
    pick_data.name = getPickName();
    pick_data.desc = mPickDescription->getValue().asString();
    pick_data.snapshot_id = mSnapshotCtrl->getImageAssetID();
    pick_data.pos_global = getPosGlobal();
    pick_data.sort_order = 0;
    pick_data.enabled = TRUE;

    LLAvatarPropertiesProcessor::getInstance()->sendPickInfoUpdate(&pick_data);

    if(mNewPick)
    {
        // Assume a successful create pick operation, make new number of picks
        // available immediately. Actual number of picks will be requested in
        // LLAvatarPropertiesProcessor::sendPickInfoUpdate and updated upon server respond.
        LLAgentPicksInfo::getInstance()->incrementNumberOfPicks();
    }
}

// static
std::string LLPanelProfilePick::createLocationText(const std::string& owner_name, const std::string& original_name, const std::string& sim_name, const LLVector3d& pos_global)
{
    std::string location_text(owner_name);
    if (!original_name.empty())
    {
        if (!location_text.empty())
        {
            location_text.append(", ");
        }
        location_text.append(original_name);

    }

    if (!sim_name.empty())
    {
        if (!location_text.empty())
        {
            location_text.append(", ");
        }
        location_text.append(sim_name);
    }

    if (!location_text.empty())
    {
        location_text.append(" ");
    }

    if (!pos_global.isNull())
    {
        S32 region_x = ll_round((F32)pos_global.mdV[VX]) % REGION_WIDTH_UNITS;
        S32 region_y = ll_round((F32)pos_global.mdV[VY]) % REGION_WIDTH_UNITS;
        S32 region_z = ll_round((F32)pos_global.mdV[VZ]);
        location_text.append(llformat(" (%d, %d, %d)", region_x, region_y, region_z));
    }
    return location_text;
}

void LLPanelProfilePick::updateTabLabel(const std::string& title)
{
    setLabel(title);
    LLTabContainer* parent = dynamic_cast<LLTabContainer*>(getParent());
    if (parent)
    {
        parent->setCurrentTabName(title);
    }
}